Trying to align radio buttons in RadioGroups in compound layout - android

I have this layout fragment. Why aren't the two radio groups aligned? I've tried with and without margin and padding in the RadioGroup.
I'm assuming that marginLeft is measured from the left edge of the radio button itself and marginRight is measured from the right of the longest radio button caption. The documentation is not clear in this respect.
Note that I've deleted any lines not related to layout (e.g. text). All text sizes are 15sp.
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/lengthImage"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="#string/length"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/lengthImage"
android:paddingLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioGroup
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/lengthMetres"
android:paddingRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="#+id/lengthFeet"
android:paddingRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:id="#+id/distanceImage"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="#string/distance"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/distanceImage"
android:paddingLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioGroup
android:orientation="vertical"
android:layout_marginLeft="200dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/distanceMile"
android:paddingRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="#+id/distanceKM"
android:paddingRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="#+id/distanceNM"
android:paddingRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
</RelativeLayout>
[EDIT]
Solution.
Hard coding the RadioGroup widths to 100dp works perfectly. I hate doing this though. I bet there's a combination of resolution, density and orientation out there that will break this!

You can fully build your layout without hard coding the 100dp.
By making few tricks with android:layout_alignLeft, android:layout_alignBottom and android:layout_alignTop you can solve your problem with the RadioGroups.
But, you will have to change the XML a little bit, because it will work only if both RadioGroups are in the same RelativeLayout.
This is your code with all adjustments:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/radio_group_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="200dp"
android:orientation="vertical" >
<RadioButton
android:id="#+id/lengthMetres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="metres" />
<RadioButton
android:id="#+id/lengthFeet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="feet" />
</RadioGroup>
<ImageView
android:id="#+id/lengthImage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignBottom="#id/radio_group_1"
android:layout_alignTop="#id/radio_group_1"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/radio_group_1"
android:layout_alignTop="#id/radio_group_1"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/lengthImage"
android:gravity="center"
android:paddingLeft="15dp"
android:text="#string/length" />
<RadioGroup
android:id="#+id/radio_group_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/radio_group_1"
android:layout_below="#id/radio_group_1"
android:orientation="vertical" >
<RadioButton
android:id="#+id/distanceMile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="mile" />
<RadioButton
android:id="#+id/distanceKM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="km" />
<RadioButton
android:id="#+id/distanceNM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="NM" />
</RadioGroup>
<ImageView
android:id="#+id/lengthImage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignBottom="#id/radio_group_2"
android:layout_alignTop="#id/radio_group_2"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/radio_group_2"
android:layout_alignTop="#id/radio_group_2"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/lengthImage"
android:gravity="center"
android:paddingLeft="15dp"
android:text="#string/length" />
</RelativeLayout>
And this is how it looks:
I think, that this solution in your specific case is applicable, but for some kind of generic solution, when you have more then two RadioGroups this solution will have to be improved.
Hope this approach could be useful for you :)

Looks like you should use android:layout_width="match_parent" and android:layout_marginLeft="200dp"(not android:marginLeft) for your RadioGroups.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/lengthImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/lengthImage"
android:paddingLeft="15dp"
android:text="length" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="200dp"
android:orientation="vertical" >
<RadioButton
android:id="#+id/lengthMetres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="meters" />
<RadioButton
android:id="#+id/lengthFeet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="feets" />
</RadioGroup>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/distanceImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/distanceImage"
android:paddingLeft="15dp"
android:text="distance" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="200dp"
android:orientation="vertical" >
<RadioButton
android:id="#+id/distanceMile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingRight="20dp"
android:text="foo" />
<RadioButton
android:id="#+id/distanceKM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="boo" />
<RadioButton
android:id="#+id/distanceNM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="moo" />
</RadioGroup>
</RelativeLayout>

Related

TextView Layout 2 lines and right aligned text

I want to achieve this layout as in screenshot: ImageView + 2 lines of Textview -> left aligned, and in the same row I want to add another textView, but at the right end of the line.
What I tried:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageViewIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_alignParentStart="true"
android:paddingEnd="10dp"
android:paddingStart="10dp"
/>
<TextView
android:id="#+id/book_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageViewIcon"
android:textSize="16sp"
android:textColor="#468bff"
android:layout_toEndOf="#+id/imageViewIcon"
/>
<TextView
android:id="#+id/author_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/book_title"
android:layout_toRightOf="#+id/imageViewIcon"
android:layout_toEndOf="#+id/imageViewIcon" />
<TextView
android:id="#+id/dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/book_title"
android:layout_toEndOf="#+id/book_title"
android:layout_centerVertical="true"
android:gravity="end"
/>
As you can see in the last TextView I used toRightOf, then gravity end. This causes however to position the last TextView over the 2 lines, so it is not aligned to the right.
Solution can be multiple . Try something like this .
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageViewIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher"
android:layout_alignParentStart="true"
android:paddingEnd="10dp"
android:paddingStart="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_toRightOf="#+id/imageViewIcon"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/dist"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="#+id/book_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageViewIcon"
android:textSize="16sp"
android:textColor="#468bff"
android:layout_toEndOf="#+id/imageViewIcon"
/>
<TextView
android:id="#+id/author_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/book_title"
android:layout_toRightOf="#+id/imageViewIcon"
android:layout_toEndOf="#+id/imageViewIcon" />
</LinearLayout>
<TextView
android:id="#+id/dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="end"
/>
</RelativeLayout>
Try the layout below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/icon" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:weightSum="100"
android:layout_marginStart="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_1"
android:textSize="20sp"
android:layout_weight="60"
android:text="SOME TITLE"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_2"
android:layout_weight="40"
android:text="Subtitle"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="150m"
android:layout_marginStart="30dp"
android:gravity="center"
android:id="#+id/tv_3"/>
</LinearLayout>
Output:

Android how to design the xml about the UI

I need to design the xml about below layout.
I try to use RelativeLayout to design, but I don't know
how to adjust the imageVivew3 in RelativeLayout.
Have anyone can teach me how to adjust the xml?
or have you nice xml design about this layout?
thank you very much.
my xml is below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relative_bg"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView1"
android:layout_centerHorizontal="true"
android:visibility="visible"
android:layout_margin="0dp"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:visibility="visible"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView3"
android:visibility="visible"
android:layout_centerVertical="true"
android:layout_below="#+id/imageView3"
android:layout_alignParentRight="true"
/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:layout_alignTop="#+id/textView1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="txt1"
android:id="#+id/textView1"
android:textColor="#color/white"
android:textSize="#dimen/common_size_large"
android:layout_below="#+id/imageView3"
android:layout_alignParentRight="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="txt2"
android:id="#+id/textView2"
android:textColor="#color/white"
android:layout_below="#+id/textView1"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Try to LinearLayout instead of RelativeLayout..
And also use android:layout_weight atttribute ...code sample are given below... put this
code to your xml.
<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="#android:color/white"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight=".75"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2"
android:layout_gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gerder"
android:textSize="12sp"
android:textStyle="bold"
android:contentDescription="#string/app_name"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:gravity="center"
android:textColor="#android:color/black"
android:fontFamily="#string/providerFontFamily"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<RadioGroup
android:id="#+id/radioGender"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginLeft="5dp"
>
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/providerGenderMale"
android:checked="true" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/providerGenderFemale" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2"
android:layout_gravity="center"
>
<TextView
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#string/providerFontFamily"
android:text="#string/age_range"
android:gravity="left"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_gravity="center"
/>
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginRight="15dp"
android:prompt="#string/country_prompt"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

Prevent a view from getting outside of the screen

I'm working with the Google Maps API v2, and I overrided getInfoContents() from InfoWindowAdapter for having a customized InfoWindow. Inside getInfoContents()I inflate an xml containing an ImageView, and three TextViews.
My problem comes when the text that is set inside the snippet is larger than the view, then the count TV it's set outside the view. This is illustrated above with some screenshots.
Here my xml layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/categoryIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/count"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/categoryIcon"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold" />
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Snippet" />
</LinearLayout>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#111177"
android:text="0"
android:textSize="20sp"
android:padding="10dp"
android:textColor="#FFF"
android:layout_toRightOf="#+id/text"
android:singleLine="true" />
</RelativeLayout>
How can I change this layout for getting the count TextView inside of the screen, and the snippet in multiline?
I want to always show the count TextView.
UPDATE:
Finally with the answer of Simon Marquis I realized a way to accomplish this. Here the new code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/categoryIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/text"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_toRightOf="#+id/categoryIcon">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold" />
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Snippeta" />
</LinearLayout>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#111177"
android:text="0"
android:textSize="20sp"
android:padding="10dp"
android:textColor="#FFF"
android:singleLine="true" />
</LinearLayout>
</RelativeLayout>
You should add this to the LinearLayout:
android:layout_width="0dp"
android:layout_weight="1"
The new layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/categoryIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/count"
android:src="#drawable/ic_launcher"/>
<LinearLayout
android:id="#+id/text"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/categoryIcon"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold" />
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Snippet" />
</LinearLayout>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#111177"
android:text="0"
android:textSize="20sp"
android:padding="10dp"
android:textColor="#FFF"
android:layout_toRightOf="#+id/text"
android:singleLine="true" />
</RelativeLayout>
One solution if you want that the count TextView always appears at right is the following:
Put the count Text View before the LinearLayout and add
android:layout_alignParentRight="true"
And add android:layout_toLeftOf="#id/count" in the Linear Layout
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#00F"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#id/count"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

Button in LinearLayout not displayed in Android

I have a button in linearlayout above the image. The image is displaying properly, but the linearlayout above the image is not displayed.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E9E0DB" >
<LinearLayout
android:id="#+id/editdialogstartedlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="5dip" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Edit"
android:textColor="#000000" />
</LinearLayout>
<com.example.masonrytest.views.ScaleImageView
android:id="#+id/profdialogphotoimageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="#+id/textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dip" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/profdialogphotoimageview"
android:text="There Is Nothing Negative In Total Exploitation Of Natural Resources. What Say?"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="normal" />
<LinearLayout
android:id="#+id/dialog_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<ImageView
android:id="#+id/list_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignBottom="#id/text1"
android:src="#drawable/picture1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/list_image"
android:layout_toRightOf="#+id/list_image"
android:padding="5dip"
android:text="By Andrew"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="25dp"
android:src="#drawable/member" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dip"
android:text="8"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:src="#drawable/udebate_fav" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"
android:text="64"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Any ideas or suggestions please?
Thanks.
Try it.
remove following property from LinearLayout.
android:layout_above="#+id/profdialogphotoimageview"
and put
android:layout_alignParentTop="true"
and also you need to put following property in "com.example.masonrytest.views.ScaleImageView"
android:layout_below="#+id/editdialogstartedlayout"
now you get the actual View which you need.
In your old code Your Button not view because of has fill-parent height so, it takes all size of the screen. and LinearLayout above of this layout that's why its gone above of the screen.
Your root level (the RelativeLayout) has children that all have fill_parent/match_parent. This means that all items are going to fill the available space. You will only see the last one (#+id/textlayout). Think about what you are trying to achieve with your layout.
If you use Eclipse, there is also a GUI you can test with.
Give id to main layout here RelativeLayout android:id="#+id/main"
and add
android:layout_below="#+id/main" to LinearLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E9E0DB" >
<LinearLayout
android:id="#+id/editdialogstartedlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="5dip"
android:layout_alignParentTop="true" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Edit"
android:textColor="#000000" />
</LinearLayout>
<com.example.masonrytest.views.ScaleImageView
android:id="#+id/profdialogphotoimageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editdialogstartedlayout" />
<LinearLayout
android:id="#+id/textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profdialogphotoimageview"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dip" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="There Is Nothing Negative In Total Exploitation Of Natural Resources. What Say?"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="normal" />
<LinearLayout
android:id="#+id/dialog_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<ImageView
android:id="#+id/list_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignBottom="#id/text1"
android:src="#drawable/picture1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/list_image"
android:layout_toRightOf="#+id/list_image"
android:padding="5dip"
android:text="By Andrew"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="25dp"
android:src="#drawable/member" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dip"
android:text="8"
android:textColor="#000000"
android:textSize="10dp"
android:textStyle="normal" />
<ImageView
android:id="#+id/list_image"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:src="#drawable/udebate_fav" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"
android:text="64"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
in the element com.example.masonrytest.views.ScaleImageView try adding the following line:
android:layout_toEndOf="#id/editdialogstartedlayout"

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