我制作了一个简单的相对布局,其中只包含3个TextView
,代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!--Why this "age" TextView is not align to parent right?-->
<TextView
android:id="@+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/name"
android:layout_alignParentRight="true"/>
<TextView
android:id="@+id/gender"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"/>
</RelativeLayout>
我希望将第二个TextView
(id =“age”)定位到右侧,因此我使用layout_alignParentRight="true"
,但是它始终显示在第一个TextView
之后(id =“名字”),为什么?为什么它没有转到父权(最右边)?
答案 0 :(得分:9)
删除它:
android:layout_toRightOf="@id/name"