【问题标题】:Header and footer in a LinearLayoutLinearLayout 中的页眉和页脚
【发布时间】:2012-09-16 01:02:05
【问题描述】:

我正在尝试实现一个垂直线性布局,其中底部有固定宽度条,顶部有固定宽度条,中间区域占据其余空间。在幼稚的实现中

<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,把剩下的垂直空间分配给它。

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

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 2011-08-17
      • 2017-03-20
      • 2012-09-23
      • 1970-01-01
      相关资源
      最近更新 更多