I was creating a XML layout for my app and I needed to align a button below a text, but because i used a LinearLayout to align horizontaly some texts with the property weight, the button stayed in a different layout and now I define the property “android:layout_below” and it doesn’t find the ID of the text.
So, someone have any suggestion that could solve this problem without using Java?
Here’s my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/text2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/text3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="text3"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/text1"
android:layout_alignParentLeft="true"
android:layout_below="@+id/text1"
android:gravity="center"
android:text="Button" />
</RelativeLayout>
EDIT:
The button has to be aligned with text1, the idea is to use three properties: align_left, align_right and align_below so the button have the same width of the text. And I have other views to set properties with the texts.
You can set id for LinearLayout:
and place the button under the layout using
To align the button under the first text you can enclose the text1 and the button with the vertical linear layout: