在使用LinearLayout的时候,子控件可以设置layout_weight。layout_weight的作用是设置子空间在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,则控件越重要。若不设置layout_weight则默认比重为0。

如果在一个LinearLayout里面放置两个Button,Button1和Button2,Button1的layout_weight设置为1,Button2的layout_weight设置为2,且两个Button的layout_width都设置为fill_parent。
复制代码 代码如下:
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">