LinearLayout minHeight 不工作 weigth=“1”

2022-09-03 03:08:21

我整个下午都试图让属性发挥作用。minHeight

我想要的是布局:linearMe

  • 当 ListView 只有几个元素时,从屏幕底部拉伸到 ListView 的底部。
  • 例如,我需要能够用图片填充linearMe布局。

随着 ListView 变得越来越大,我希望布局能够:linearMe

  • 具有固定的高度(同时位于屏幕底部)和列表视图以允许滚动。

我的问题是布局越来越小,因为ListView中有更多的元素。当有足够的元素供 listView 填充屏幕时,布局就消失了。在这种情况下,看起来是无用的。linearMelinearMeminHeight

<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent" >

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/linearMe"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#FF0000"
    android:minHeight="200dp" />

</LinearLayout>

enter image description hereenter image description here

我希望你能帮助我!:)


答案 1

也添加到 ListView。将它们(list和linearMe)属性更改为“删除'minHeight”。android:layout_weight="1"android:layout_height"match_parent"

这样,每个视图将占据屏幕的一半。


答案 2

您可能希望尝试使用“视图”而不是“线性布局”来尝试间隔布局。视图组类有时处理布局的方式略有不同。