在LinearLayout
我们可以使用 Layout_Weight 水平填充元素,这使它们占据所有宽度,每个宽度取决于它们的 Layout_Weight 值(或比率)。我的问题是在RelativeLayout
. 没有像 Layout_Weight 这样的属性。我RelativeLayout
在我的项目中使用 a ,它包含 4 个按钮,它们需要位于屏幕底部并且必须填满整个宽度。如果我使用硬编码Layout_Width="20dp"
或类似的东西。当我将方向从纵向更改为横向时,它会产生问题,反之亦然。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/feed_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/feed"
android:textColor="#FF000000" />
<Button
android:id="@+id/iwant_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/feed_button"
android:text="@string/iwant"
android:textColor="#FF000000" />
<Button
android:id="@+id/share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/iwant_button"
android:text="@string/share"
android:textColor="#FF000000" />
<Button
android:id="@+id/profile_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/share_button"
android:text="@string/profile"
android:textColor="#FF000000" />
</RelativeLayout>