本例使用给LinearLayout 宽度和高度设为wrap_content 和将子View大小设为match_parent ,从而实现所有子View具有同样的大小:
- wrap_content: 告诉View使用能包含其内容的尺寸 (类似于WinForm 中AutoSize)。
- fill_parent(或match_parent 从Level 8起): 子View扩展为其父容器尺寸。
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:background=”@drawable/blue”
android:padding=”20dip”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content“>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_6_one”/>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_6_two”/>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_6_three”/>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_6_four”/>
</LinearLayout>