本例使用给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>
本文介绍如何通过设置LinearLayout的宽度和高度属性来确保所有子View具有相同的大小。通过使用wrap_content和match_parent属性组合,可以实现子View自动调整大小以匹配父容器。

760

被折叠的 条评论
为什么被折叠?



