本例介绍了LinearLayout 水平布局的基本用法:
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”horizontal”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:background=”@drawable/red”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″/>
<TextView
android:background=”@drawable/green”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″/>
<TextView
android:background=”@drawable/blue”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″/>
<TextView
android:background=”@drawable/yellow”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″/>
</LinearLayout>
注意这里四个TextView 的权重都设为1,因此将平均分配大小。使用权重的一个基本算法,LinearLayout 剩余的空间有所有有“权重”的View按照其权值按比例分配大小。
LinearLayout水平布局详解
本文介绍了一个使用LinearLayout实现的水平布局示例。通过设置TextView的权重为1,使得这些视图在LinearLayout中平均分配空间。文章详细解释了如何利用权重属性来调整视图的大小。


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



