Adding and image beside a spinner in an android layout - android

I just want to add an image beside the Spinner in my layout. I tried align:layout_gravity = "right" for the image, but this moved the image to the right side in the layout and below the Spinner present in the same layout. What I want is for the image to be displayed exactly besides the Spinner. Below is the xml layout file:
<LinearLayout
android:id="#+id/topLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:background="#color/headingBgColor"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/yourName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Group"
android:textColor="#color/black" />
</ImageView>
</LinearLayout>
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:padding="5sp" >
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tasks"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Messages"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Groups"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
<Button
android:id="#+id/deleteBlockLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MyProfile"
android:textSize="#dimen/font_size_10"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/centerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/topLayout"
android:orientation="vertical"
android:padding="10sp" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:paddingTop="20dip" />
<ImageView
android:id="#+id/imageButton"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_gravity="right"
android:src="#drawable/contacts" />
<LinearLayout
android:id="#+id/centerLqayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10sp" >
<CheckBox
android:id="#+id/sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SMS"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textColor="#color/black" />
</LinearLayout>
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:gravity="top"
android:inputType="textPostalAddress" >
<requestFocus />
</EditText>
<Button
android:id="#+id/deleteBlockLog1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Send"
android:textSize="#dimen/font_size_15" />
</LinearLayout>

LinearLayout with orientation set to vertical will put the child views one below other. You have two options:
You either wrap the Spinner and the ImageView in another LinearLayout with orientation set to horizontal so the two views end up on the same line.
Example:
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal">
<Spinner
android:id="#+id/spinner1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:paddingTop="20dip" />
<ImageView
android:id="#+id/imageButton"
android:layout_width="100dp"
android:layout_height="70dp"
android:src="#drawable/contacts" />
</LinearLayout>
You use a layout that allows the children to be placed relative to others(like a RelativeLayout) instead of the parent LinearLayout with the id centerLayout.

Related

how to set one linear layout below another linear layout in android

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation=""
android:layout_marginTop="40dp" >
<LinearLayout
android:id="#+id/imagecontainlayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Status:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_weight=".75" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="295dp"
android:layout_height="44dp"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Status:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
Here is my Xml am trying to set imagecontainlayout linear layout to another linear layout containing another linear layout with some gap but i dont know where am doing mistake in my code my current screen is coming like this .
my current screen is coming like this while i want there first layout below another layout with some gap please help me where am doing mistake.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/round_bg"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:singleLine="true"
android:text="Step:"
android:textColor="#0060a4"
android:textSize="15dp" />
<TextView
android:id="#+id/step"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:textColor="#0060a4"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
use this code it will Help u .

android - LinearLayout (Horizontal) - auto space between items

I have an android LinearLayout and at the button I have buttons that I want to display in one line - I've put the in a horizontal layout so it will be next to each other - so far so good.
Here is my problem - the buttons are right next to each other, and what I would like is to have them take the screen with spaces between them and padding from the right and left to the first and last buttons are not stuck to the border of the screen.
here's my layout xml (just the LinearLayout (Horizontal) part):
<LinearLayout
android:id="#+id/btnHelpLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/btnHelp"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_help" />
<TextView
android:id="#+id/tvHelp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_help"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnShareLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/btnShare"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_share" />
<TextView
android:id="#+id/tvShare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_share"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnAboutLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="28dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/btnAbout"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_about" />
<TextView
android:id="#+id/tvAbout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_about"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnSettingsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/btnSettings"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_settings" />
<TextView
android:id="#+id/tvSettings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_settings"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
how can I have it centered and with spaces?
thanks
Change the child container's (the LinearLayout's btnHelpLayout, btnShareLayout, btnAboutLayout and btnSettingsLayout) android:layout_width attributes to "0dip" and set a new attribute android:layout_weight="1" in all child containers (Not the Buttons and TextViews).
This will make them occupy the same space and give you a uniform look.
<LinearLayout
android:id="#+id/btnHelpLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/btnHelp"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_help" />
<TextView
android:id="#+id/tvHelp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_help"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnShareLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/btnShare"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_share" />
<TextView
android:id="#+id/tvShare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_share"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnAboutLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="28dp"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/btnAbout"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_about" />
<TextView
android:id="#+id/tvAbout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_about"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnSettingsLayout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/btnSettings"
android:layout_width="52dp"
android:layout_height="52dp"
android:background="#drawable/btn_settings" />
<TextView
android:id="#+id/tvSettings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/btn_settings"
android:textColor="#fff" />
</LinearLayout>

Linear and Relative Layout aligment

I am unable to get the below shown layout..can anyone let me know how to achieve this layout ?
This is what I have but unable to get the specified layout.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/someimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#88FF0000" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right">
<TextView
android:id="#+id/txtview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtview2"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:layout_below="#id/txtview1"/>
<TextView
android:id="#+id/txtview3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="#003399"
android:textSize="19sp"
android:textStyle="bold"
android:layout_below="#id/txtview2"/>
</RelativeLayout>
</LinearLayout>
I want to get this as final layout:
You can use a single RelativeLayout
You can remove the unwanted RelativeLayout with black background. (Just to differentiate i added another relative layout with black background)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="15dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:layout_below="#+id/imageView1" >
</RelativeLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="16dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="54dp"
android:layout_marginTop="14dp"
android:text="TextView" />
</RelativeLayout>
Edit:
You can also center the text in TextView and use match_parent for the layout width and remove the unwanted realtive layout. Notice the change android:layout_toRightOf="#+id/imageView1" in the below code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView2"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="15dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView3"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="15dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="TextView" />
</RelativeLayout>
snap
You need to set the layout_width of all TextViews to fill_parent.
Note that your code should not even compile because the layout_width attribute is mandatory, and you don't specify it for the second TextView, and it also does not have a style attribute where it might be specified.
The below hierarchy can also do what you want:
Linear-Horizontal
Linear-Vertical
imageview
Linear-Horizontal
textview
textview
textview
What about a vertical linear layout where you put the image view in. Also put a horizontal linear layout in, where you place the textviews. Set the vertical height to wrap content and the horizontal to match parent.
Let me know if this works for you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/someimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#88FF0000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<TextView
android:id="#+id/txtview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="TextView1"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtview1"
android:focusable="false"
android:gravity="center"
android:text="TextView2" />
<TextView
android:id="#+id/txtview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp"
android:textStyle="bold"
android:gravity="center"
android:text="Textview 3"
android:layout_below="#id/txtview2"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

Switch between two or more edit text in android

Suppose I have two or more EditTextview in my layout and at run time by mistake I selected 2nd view and filled it with text; now I want to go to previous EditText view and on touch gain it's focus to write some text inside it.
But I am unable to do this. I can't gain focus of view and write it on click that particular view.
See the code below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/wall">
<EditText
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:textSize="30dp"
android:focusable="true"
android:hint="#string/Title" />
<EditText
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="350dp"
android:textSize="25dp"
android:paddingTop="45dp"
android:gravity="top"
android:inputType="textMultiLine|textNoSuggestions"
android:ems="10"
android:focusable="true"
android:hint="#string/program" />
<TextView
android:id="#+id/CalDisplay"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:textSize="20dp"
android:layout_below="#+id/save" />
<Button
android:id="#+id/Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/body"
android:layout_toRightOf="#+id/RunProgram"
android:background="#drawable/custom_button"
android:textColor="#ffffff"
android:text="#string/Calculate" />
<Button
android:id="#+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/Calculate"
android:layout_alignBottom="#+id/Calculate"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/RunProgram"
android:background="#drawable/custom_button"
android:textColor="#ffffff"
android:text="#string/Save"
/>
<Button
android:id="#+id/RunProgram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/body"
android:layout_centerHorizontal="true"
android:background="#drawable/custom_button"
android:textColor="#ffffff"
android:text="#string/Run" />
</RelativeLayout>
Try this...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:hint="Title"
android:textSize="15dp" />
<EditText
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="350dp"
android:layout_below="#+id/title"
android:layout_marginTop="5dp"
android:gravity="left"
android:hint="program"
android:inputType="textMultiLine|textNoSuggestions"
android:textSize="15dp" />
<TextView
android:id="#+id/CalDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/save"
android:textSize="20dp" />
<LinearLayout
android:id="#+id/linearButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/body" >
<Button
android:id="#+id/Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Calculate"
android:textColor="#ffffff" />
<Button
android:id="#+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"
android:textColor="#ffffff" />
<Button
android:id="#+id/RunProgram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Run"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
Replace RelativeLayout with LinearLayout. Because it seems like your EditText are overlapping each other (causing the problem in getting focus), or at least add some respective aligning to them.
For example, add the following to your second EditText:
android:layout_below="#id/title"

Center Button horizontally doesn't work

hy!
I want to center my button horizontally, but this never work.
My Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minage"
android:layout_alignParentLeft="true"
android:padding="5dp" />
<TextView
android:id="#+id/ml_minage_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"/>
</RelativeLayout>
<SeekBar
android:id="#+id/ml_minage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/maxage"
android:padding="5dp"/>
<TextView
android:id="#+id/ml_maxage_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/ml_maxage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distance"
android:padding="5dp" />
<TextView
android:id="#+id/ml_distance_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/ml_distance"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gender"
android:padding="5dp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="#drawable/rbon" >
<RadioButton
android:id="#+id/ml_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:button="#drawable/rbselector"
android:checked="true"
android:drawablePadding="10dp"
android:text="#string/rb_female"
android:textColor="#000000"
android:paddingLeft="42dp" />
<RadioButton
android:id="#+id/ml_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rb_male"
android:button="#drawable/rbselector"
android:layout_margin="5dp"
android:textColor="#000000"
android:paddingLeft="42dp"
/>
</RadioGroup>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/ml_stbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#drawable/custom_button"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:padding="10dp"
android:text="Flirt"
android:textColor="#ffffff"
android:textSize="12pt"
android:typeface="serif" />
</RelativeLayout>
</LinearLayout>
this xml doesn't fit the button in the middle please help.
The problem is that the RelativeLayout does not span the width of the page, it's width is wrap_content. The button is centered in the RelativeLayout, but that layout is only as wide as the button, and is mashed up against the left side of the screen.
Make the inner RelativeLayout's width as match_parent.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/ml_stbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#drawable/custom_button"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="10dp"
android:text="Flirt"
android:textColor="#ffffff"
android:textSize="12pt"
android:typeface="serif" />
</RelativeLayout>
This isn't speaking directly to your question, but your view hierarchy is too complicated. I suggest you replace all of the LinearLayout and RelativeLayout elements with a single RelativeLayout that spans the whole thing.

Categories

Resources