- xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android&#61;"http://schemas.android.com/apk/res/android"
- android:orientation&#61;"vertical"
- android:layout_width&#61;"fill_parent" android:layout_height&#61;"fill_parent">
- <TextView android:id&#61;"&#64;&#43;id/sample_1"
- android:background&#61;"&#64;color/red" android:layout_weight&#61;"1"
- android:layout_width&#61;"fill_parent" android:layout_height&#61;"0dip" />
- <TextView android:id&#61;"&#64;&#43;id/sample_2"
- android:background&#61;"&#64;color/black" android:layout_weight&#61;"2"
- android:layout_width&#61;"fill_parent" android:layout_height&#61;"0dip" />
- <TextView android:id&#61;"&#64;&#43;id/sample_3"
- android:background&#61;"&#64;color/white" android:layout_weight&#61;"3"
- android:layout_width&#61;"fill_parent" android:layout_height&#61;"0dip" />
- <TextView android:id&#61;"&#64;&#43;id/sample_4"
- android:background&#61;"&#64;color/blue" android:layout_weight&#61;"4"
- android:layout_width&#61;"fill_parent" android:layout_height&#61;"0dip" />
- LinearLayout>
上面代码显示出来之后&#xff0c;sample_1&#xff1a;sample_2&#xff1a;sample_3&#xff1a;sample_4高度比&#61;1&#xff1a;2&#xff1a;3&#xff1a;4。 很重要的一点是&#xff0c;高度属性要设定为0&#xff0c;绝对不能设定为fill_parent&#xff0c;不然就不会成比例了&#xff01;这是在布局是垂直布局时候的情况&#xff0c;水平时&#xff0c;则定义宽度属性为0&#xff01;