I am using a ImageView, to be exactly it is an ImageMap extending an ImageView, in a ScrollView with the following part of code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ctc="http://schemas.android.com/apk/res/de.svennergr.htn"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/backrepeat"
android:orientation="vertical"
android:padding="10dp"
android:weightSum="1" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:id="#+id/login_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="0.3333"
android:paddingTop="10dp"
android:text="Login:" />
<TextView
android:id="#+id/password_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3333"
android:paddingTop="10dp"
android:text="Password:" />
<TextView
android:id="#+id/email_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3333"
android:paddingTop="10dp"
android:text="E-Mail:"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1" >
<EditText
android:id="#+id/login_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3333"
android:ems="10" >
</EditText>
<EditText
android:id="#+id/passwd_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3333"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="#+id/email_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3333"
android:ems="10"
android:inputType="textEmailAddress"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/button"
android:text="Login"
android:textColor="#color/button_start" />
<Button
android:id="#+id/register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="3dp"
android:background="#drawable/button"
android:text="#string/register"
android:textColor="#color/button_start" />
<de.svennergr.htn.ImageMap
android:id="#+id/imap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/europa"
ctc:map="europa" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I've posted the whole XML-Code to get you a better overview.
The Imageview should display the Image with "fill_parent" to the bottom of the display, but the image is beeing resized and is not beeing displayed to the bottom:
Thanks for your help.
try adding this property to your scrollview:
android:FillViewport="true"
Edited.
Related
LinearLayout with editText on the bottom overlays the content of scrollView, which is filled programmatically.
How to avoid this please?
I have simplified the XML in vain in my first version of this message.
I have added the full code now
I'd like to keep my editText height expandable.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/backNormal"
android:orientation="vertical"
>
<include layout="#layout/adview"
android:layout_alignParentTop="true"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal"
android:background="#color/back1"
android:layout_below="#+id/adView"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:id="#+id/textChatSubjectTitle"
android:text='Subject'
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_weight="5"
android:layout_height="wrap_content"
android:textColor="#color/text1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:orientation="horizontal"
>
<TextView
android:id="#+id/textChatActn"
android:text='0'
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/textWhite"
android:background="#color/gray"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<TextView
android:id="#+id/textChatUsers"
android:text='users'
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/darkGray"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="normal"
/>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageChatImageTitle"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="right"
/>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollChat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="vertical"
android:layout_below="#+id/top"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/back1"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="#+id/buttonClip"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/clip32"
android:layout_weight="1"
android:layout_gravity= "center_vertical|center_horizontal"
/>
<EditText
android:id="#+id/editChatMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapSentences"
android:minLines="1"
android:gravity="top|left"
android:maxLines="5"
android:maxLength="500"
android:layout_marginRight="5dp"
android:text=''
android:layout_gravity= "center_vertical|center_horizontal"
android:textColor="#color/text1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="5"
android:background="#drawable/edit"
android:scrollHorizontally="false"
android:cursorVisible="true"
android:textCursorDrawable="#null"
/>
<Button
android:id="#+id/buttonChatSend"
android:text='>'
android:layout_marginRight="5dp"
android:gravity="center"
android:layout_gravity= "center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/darkGray"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:background="#drawable/button_normal"
/>
</LinearLayout>
</RelativeLayout>
Any ideas please?
Thanks!
I suggest using Relative layout for parent. And then add the rule above.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/llButton"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/llButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:id="#+id/editMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="top|left"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="5"
android:minLines="3"
android:scrollHorizontally="false" />
<Button
android:id="#+id/buttonSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text='send'
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
Please try the below code, if it solves your problem.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="1200dp"
android:background="#ff0000"
android:orientation="vertical"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/editMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#drawable/edit"
android:gravity="top|left"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="5"
android:minLines="3"
android:textColor="#color/text1"
android:scrollHorizontally="false"
/>
<Button
android:id="#+id/buttonSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#drawable/button_normal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I want to create a login screen. I want to have the heading at the top, leave some white space and then have the user name and passwords each in one line. Then, I want to leave some more white space at the bottom.
Currently, I haven't tried to put the password TextView and EditTect in a single line because there is some error with the LinearLayout corresponding to the user name due to which it is not rendering. Could you please help me figure out? My XML file is below -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="#string/welcome_message"
android:textSize="20sp" />
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="User Name" />
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="0sp"
android:layout_weight="1"
android:text="Password" />
<EditText
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="1"
android:inputType="textPassword" />
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4" />
</LinearLayout>
Take a look if this what are you looking for:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="0.5" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="3"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="welcome_message"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="1" >
<TextView
android:id="#+id/text_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:lines="1"
android:text="Login:"
android:textSize="13dp" />
<EditText
android:id="#+id/edt_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.2"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4" >
<TextView
android:id="#+id/text_senha"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:maxLines="1"
android:text="Senha:" />
<EditText
android:id="#+id/edt_senha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.2"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="0.5" />
</LinearLayout>
use layout margin and padding settings to leaving space for views.
i recommend using relative layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="2"
android:layout_marginTop="30dip"
android:gravity="center_horizontal"
android:text="welcome_message"
android:textSize="20sp" />
<View
android:layout_width="fill_parent"
android:layout_height="0sp"
android:layout_weight="4" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:padding="10dip"
android:weightSum="2"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="User Name" />
<EditText
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:padding="10dip"
android:weightSum="2"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Password" />
<EditText
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
I am creating a application for android, wherein i am facing one strange kind of problem. The problem is that I've positioned the button in the center of the screen which is shown the same way in the GRAPHICAL LAYOUT of the file, but when i run the application in emulator the button is positioned more towards the right side and not centered. Can anyone point out the problem.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:panel="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCC"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.miscwidgets.widget.Panel
android:id="#+id/mytopPanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dip"
panel:animationDuration="1000"
panel:closedHandle="#drawable/top_switcher_collapsed_background"
panel:content="#+id/mypanelContent"
panel:handle="#+id/mypanelHandle"
panel:linearFlying="true"
panel:openedHandle="#drawable/top_switcher_expanded_background"
panel:position="top" >
<Button
android:id="#+id/mypanelHandle"
android:layout_width="fill_parent"
android:layout_height="33dip"
android:paddingRight="50dp" />
<LinearLayout
android:id="#+id/mypanelContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/editTextUserName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_marginTop="6dp"
android:hint="#string/editUserName" >
</EditText>
<EditText
android:id="#+id/editTextPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:hint="#string/editUserPwd" >
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#323299"
android:gravity="center"
android:padding="4dip"
android:text="#string/drpDwnTxt"
android:textColor="#eee"
android:textSize="16dip"
android:textStyle="bold" />
</LinearLayout>
</org.miscwidgets.widget.Panel>
<EditText
android:id="#+id/editTextNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_marginTop="6dp"
android:hint="#string/editNumber" >
</EditText>
<EditText
android:id="#+id/editTextMessage"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="3dp"
android:hint="#string/editPwd" >
</EditText>
<Spinner
android:id="#+id/spinnerGateway"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:entries="#array/spinnerList"
android:prompt="#string/spinnerPrompt" />
<Button
android:id="#+id/btnSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:onClick="save"
android:text="#string/StrbtnSend" >
</Button>
</LinearLayout>
</FrameLayout>
Please try to change with this code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:panel="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCC"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.miscwidgets.widget.Panel
android:id="#+id/mytopPanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dip"
panel:animationDuration="1000"
panel:closedHandle="#drawable/top_switcher_collapsed_background"
panel:content="#+id/mypanelContent"
panel:handle="#+id/mypanelHandle"
panel:linearFlying="true"
panel:openedHandle="#drawable/top_switcher_expanded_background"
panel:position="top" >
<Button
android:id="#+id/mypanelHandle"
android:layout_width="fill_parent"
android:layout_height="33dip"
android:gravity="center" />
<LinearLayout
android:id="#+id/mypanelContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/editTextUserName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_marginTop="6dp"
android:hint="#string/editUserName" >
</EditText>
<EditText
android:id="#+id/editTextPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:hint="#string/editUserPwd" >
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#323299"
android:gravity="center"
android:padding="4dip"
android:text="#string/drpDwnTxt"
android:textColor="#eee"
android:textSize="16dip"
android:textStyle="bold" />
</LinearLayout>
</org.miscwidgets.widget.Panel>
<EditText
android:id="#+id/editTextNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_marginTop="6dp"
android:hint="#string/editNumber" >
</EditText>
<EditText
android:id="#+id/editTextMessage"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="3dp"
android:hint="#string/editPwd" >
</EditText>
<Spinner
android:id="#+id/spinnerGateway"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:entries="#array/spinnerList"
android:prompt="#string/spinnerPrompt" />
<Button
android:id="#+id/btnSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:onClick="save"
android:text="#string/StrbtnSend" >
</Button>
</LinearLayout>
</FrameLayout>
This new layout file has done the job for me, just one small error was creating the trouble.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:panel="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCC"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<org.miscwidgets.widget.Panel
android:id="#+id/mytopPanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
panel:animationDuration="1000"
panel:closedHandle="#drawable/top_switcher_collapsed_background"
panel:content="#+id/mypanelContent"
panel:handle="#+id/mypanelHandle"
panel:linearFlying="true"
panel:openedHandle="#drawable/top_switcher_expanded_background"
panel:position="top" >
<Button
android:id="#+id/mypanelHandle"
android:layout_width="wrap_content"
android:layout_height="33dip"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:id="#+id/mypanelContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/editTextUserName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_marginTop="6dp"
android:hint="#string/editUserName" >
</EditText>
<EditText
android:id="#+id/editTextPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:hint="#string/editUserPwd" >
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#323299"
android:gravity="center"
android:padding="4dip"
android:text="#string/drpDwnTxt"
android:textColor="#eee"
android:textSize="16dip"
android:textStyle="bold" />
</LinearLayout>
</org.miscwidgets.widget.Panel>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<AutoCompleteTextView
android:id="#+id/mmWhoNo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#+id/btnContact"
android:hint="To: Type to search"
android:textSize="13sp" />
<Button
android:id="#+id/btnContact"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:background="#drawable/contacts_icon"
android:textSize="18dp" >
</Button>
</RelativeLayout>
<EditText
android:id="#+id/editTextMessage"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="3dp"
android:hint="#string/editPwd" >
</EditText>
<Spinner
android:id="#+id/spinnerGateway"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:entries="#array/spinnerList"
android:prompt="#string/spinnerPrompt" />
<Button
android:id="#+id/btnSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="#string/StrbtnSend" >
</Button>
<TextView
android:id="#+id/txtAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Designed By - Tapan Desai" />
</LinearLayout>
</FrameLayout>
remove padding from the button xml and set gravity to center
layout_gravity="center"//can also set horizontal or vertical
and make sure you are not setting margin or padding in your java class where you are accessing it.
I am trying to design a screen like this one in Android:
I have all buttons, background and images in separate PNG files, but I can't get it done!
I don't know how to put the two buttons inside the background and I am having troubles with the distances from the borders as well.
Here is what I have so far:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/fundo_tela">
<ImageView
android:id="#+id/imgtopo"
android:src="#drawable/topo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/telaInicio"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#fff"
android:textSize="20dp" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/fundoBotoes" >
<Button android:id="#+id/Camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/cameraBselector">
</Button>
<Button
android:id="#+id/Galeria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/galleryBselector">
</Button>
</LinearLayout>
<Button
android:id="#+id/Pedidos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/pedidosBselector"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
>
</Button>
</LinearLayout>
When you say "the two buttons" I assume it is the Gallery and Camera buttons you are talking about.
If I understand correctly you can do something like this (I have not testet it properly, so you might want to make some additional changes)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical"
android:background="#000000"
android:gravity="center"
>
<Button
android:id="#+id/Camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5sp"
android:background="#color/cameraBselector"
>
</Button>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_margin="3sp"
android:background="#41383C"
/>
<Button
android:id="#+id/Galeria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3sp"
android:background="#color/galleryBselector"
/>
</LinearLayout>
If I misunderstood something please let me know.
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/fundo_tela"
android:layout_weight="100"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="20"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgtopo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/topo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/telaInicio"
android:textColor="#fff"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="60"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/fundoBotoes"
android:orientation="vertical" >
<Button
android:id="#+id/Camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/cameraBselector" >
</Button>
<Button
android:id="#+id/Galeria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/galleryBselector" >
</Button>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="20"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<Button
android:id="#+id/Pedidos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:background="#color/pedidosBselector" >
</Button>
</LinearLayout>
</LinearLayout>
Only group the first imageview and text in a Linearlayout and the last button in other LinearLayout. With the weight attribute work like a percent, this example is 20% top, 60% body and 20% footer.
Did to look exactly what you wanted.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgtopo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="10dp"
android:text="Selecione a opção desejada:"
android:textColor="#fff"
android:textSize="18dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.90"
android:background="#android:color/black"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/ButtonCamera"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:layout_margin="10dp"
android:drawablePadding="-5sp"
android:drawableTop="#android:drawable/ic_menu_camera"
android:text="Tirar Foto"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/ButtonSlideShow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:layout_margin="10dp"
android:drawablePadding="-5sp"
android:drawableTop="#android:drawable/ic_menu_slideshow"
android:text="Galeria de Foto"
android:textColor="#FFFFFF" />
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Meus Pedidos" />
</LinearLayout>
EDITED: I HAVE FOUND THE SOLUTION MYSELF. THANK YOU!
I want to create the following screen for an Android App:
Right now I have this:
with this code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".65"
android:weightSum="5" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TOURNAMENT: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"/>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="GAME: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="BEST OF: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="BRACKET STYLE: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".35"
android:weightSum="5" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp" />
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:text="CANCEL" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/button2"
android:text="CREATE" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
The text can be aligned to the right using android:gravity="right", but how can I make it
centered vertically?
--> AISHH, it's: android:gravity="center_vertical|right"
Thank you!!
Well TableLayout is not a good ideea. You should try using a RelativeLayout and some LinearLayout nested inside.
Try something like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:id="#+id/first_linear"
android:orientation="vertical">
<!-- Note that for text view,and editText you might need to use certain values (dip values) cuz wrap content will try to arrange the view -->
<TextView
android:id="#+id/first_text_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id = "#+id/first_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<!-- we align all the following linearlayouts below the first -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/first_linear"
android:id="#+id/second_linear"
android:orientation="vertical">
<TextView
android:id="#+id/second_text_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id = "#+id/second_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<!-- add all the layouts like those from above -->
<!-- ...... -->
<!-- after you added all the fields you can add a linear layout containing two buttons to float below the last one -->
I've done a similar layout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="fill_parent"
>
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0">
<LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="fill_parent">
<TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:stretchColumns="1" android:shrinkColumns="1">
<TableRow android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:text="Value1" android:gravity="right" />
<EditText android:singleLine="true" android:id="#+id/editTextVal1" />
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:text="Long name value2" android:gravity="right" />
<EditText android:singleLine="true" android:id="#+id/editTextVal1" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Save" />
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel" />
</LinearLayout>
</LinearLayout>
There's a scroll panel in there to have the buttons on the bottom of the screen at all times, in case your configuration goes longer.
So this is the implementation I came up with. Not the best but worked for me :)
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".65"
android:weightSum="5"
android:paddingTop="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TOURNAMENT: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="GAME: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="BEST OF: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="BRACKET STYLE: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
<!-- fill up the space so that the components on top are displayed correctly -->
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".35"
android:weightSum="5"
android:paddingTop="10dp" >
<EditText
android:id="#+id/tourName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="center_vertical|left" />
<Spinner
android:id="#+id/spinGameName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="center_vertical|left" />
<Spinner
android:id="#+id/spinBestOf"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="center_vertical|left" />
<Spinner
android:id="#+id/spinBracketType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="center_vertical|left" />
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:text="CANCEL" />
<Button
android:id="#+id/btnCreate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btnCancel"
android:text="CREATE" />
</RelativeLayout>
</LinearLayout>