我知道你可以使用线性布局的权重参数来使两个字段对齐。我的目标是确保屏幕左半部分由一个文本字段使用,右半部分由另一个文本字段使用(我说的是宽度)。 如何做到这一点?
我知道你可以使用线性布局的权重参数来使两个字段对齐。我的目标是确保屏幕左半部分由一个文本字段使用,右半部分由另一个文本字段使用(我说的是宽度)。 如何做到这一点?
使用“隐藏视图”,高度和宽度都为零,放置在中心,并将文本视图放在两侧。使用父级对齐设置左右。
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View android:id="@+id/dummy"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_centerInParent="true"/>
<TextView
android:layout_alignRight="@id/dummy"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_alignLeft="@id/dummy"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
使用RelativeLayout作为父布局是不可能实现这个效果的。你需要将这些TextView放在一个LinearLayout中,并使用layout weight设置宽度。