Reputation: 1
When I declare 3 TextViews in RelativeLayout, 'textA', 'textB', and 'textC'. The textC should appear below textB. But when run, the textC displayed in improper position (at the top-left of screen). I don't know can textC use android:layout_below to textB.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent" >
<TextView
android:id="@+id/textA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:text="This is TextA : " />
<TextView
android:id="@+id/textB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/textA"
android:layout_alignBaseline="@id/textA"
android:text="this is textB" />
<TextView
android:id="@+id/textC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/textB"
android:text="This is TextC" />
</RelativeLayout>
Upvotes: 0
Views: 148
Reputation: 1
It cannot use vertical alignment to the elements that use alignBaseline to other elements. Then in this case in 'textB' change alignBaseline to be alignTop like in the code.
<TextView
android:id="@+id/textB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/textA"
android:layout_alignTop="@id/textA"
android:text="this is textB" />
Using this way it will support muti-line for textB.
Upvotes: 0
Reputation: 307
You can also change
android:layout_below="@id/textA"
to textC
The complete Example would look:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent" >
<TextView
android:id="@+id/textA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:text="This is TextA : " />
<TextView
android:id="@+id/textB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/textA"
android:layout_alignBaseline="@+id/textA"
android:text="this is textB" />
<TextView
android:id="@+id/textC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textB"
android:layout_below="@+id/textA"
android:text="This is TextC" />
Upvotes: 2
Reputation: 23638
Just make below changes for the TextView3
:
<TextView android:id="@+id/textC" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/textB" android:layout_below="@+id/textA" android:text="This is TextC" />
Upvotes: 0