您必须设置元素的权重属性.为LinearLayout创建三个RelativeLayouts作为子项,并设置权重0.15,0.70,0.15.然后将按钮添加到第二个RelativeLayout(重量为0.70的那个).
像这样:
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/layoutContainer" android:orientation="horizontal">
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15">
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.7">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
android:text="Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
android:text="Button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
android:text="Button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15">
为什么重量为0.15,0.7和0.15?因为总重量是1,而0.7是总重量的70%.
结果:
编辑:感谢@SimonVeloper指出方向应该是水平的而不是垂直的,并且@Andrew指出权重可以是小数而不是整数.