LinearLayout中的页眉和页脚

时间:2012-09-16 01:02:06

标签: android android-layout

我正在尝试实现一个垂直LinearLayout,其中底部有固定宽度条,顶部有固定宽度条,中间区域占据空间的其余部分。在天真的实现中

<LinearLayout android:layout_height="fill_parent"
    android:orientation="vertical" >

    <View android:layout_height="50sp"/>

    <View android:layout_height="fill_parent"/>

    <View android:layout_height="50sp"/>
</LinearLayout>

顶部栏位于那里,但底栏是隐形的。我猜布局过程在中间视图上遇到fill_parent,并为其分配剩余的垂直空间。

是否有某种重力/重量技巧会使布局识别并显示底栏?

1 个答案:

答案 0 :(得分:2)

尝试使用重量设置中间部分高度,如下所示。

<View android:layout_height="50dp"/>

<View android:layout_height="0dp"
      android:layout_weight="1"
 />

<View android:layout_height="50dp"/>

这将首先绘制顶部和底部,然后用该视图填充所有(weight =“1”)REMAINING高度