<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_weight="1" />
<Button
android:layout_width="fill_parent"
android:layout_weight="1" />
<Button
android:layout_width="fill_parent"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
现在,如果您将第三个按钮设置为可见,其他两个按钮将调整大小以在屏幕上显示 3 个按钮。水平布局中的相同视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="horizontal" >
<Button
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>