【发布时间】:2014-10-22 12:15:30
【问题描述】:
我需要在一个垂直的LinearLayout 中排列两个ListViews,这样第二个ListView 将位于第一个ListView 的最后一项的末尾。
如果 ListView1 为空,则视图应该是这样的。
随着 ListView1.size() 的增加,ListView2 应该被拉低到一个极限。
ListView1 达到固定高度(或重量),它应该停止扩展并开始滚动。
我认为android中没有方法为View设置maxHeight。
我已经尝试了几乎所有的 layout_height="wrap_content" 组合,两个 ListView 的固定高度和权重。在所有情况下, 第一个要求(image1)将失败:ListView1 不会在顶部 否则最后一个要求(image3) 将失败:ListView2 将被推出屏幕。
任何帮助或建议将不胜感激。提前致谢。
编辑:
我当前的代码是:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<ListView
android:id="@+id/myOrderListView"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.6" >
</ListView>
<ListView
android:id="@+id/myCompletedOrderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0.4" >
</ListView>
</LinearLayout>
我尝试过不同的重量组合,例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<ListView
android:id="@+id/myOrderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.6" >
</ListView>
<ListView
android:id="@+id/myCompletedOrderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0.4" >
</ListView>
</LinearLayout>
但它会满足最后一个要求。
Edit2: @dangVarmit
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<ListView
android:id="@+id/myOrderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<ListView
android:id="@+id/myCompletedOrderListView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="20dp" >
</ListView>
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
如果你是这个意思,它仍然失败 req3。
【问题讨论】:
-
到目前为止你尝试了什么?
-
反对票意味着你不知道?或者你不会帮忙?或者我不应该问?或者它是一个错误的问题?还是没有解决方案?要么 ?我花了两天多的时间,我找不到蚂蚁解决方案。
-
尝试将您的第一个 xml 中的 android:layout_height 更改为 android:layout_height="0dp",就像您对第一个 ListView 所做的那样
-
@JuanAguilarGuisado 已经尝试过了(ListView2 的 layout_height="0dp")。但没有运气:-(
-
@Vijeesh 尝试这个哪个要求失败了?首先?我的意思是...如果它是第一个,您可以尝试将 ListView1 的可见性设置为 ListView.GONE 当它的大小为 0 时。这样做,它不会占用您的空间;)祝您好运!
标签: android android-layout listview android-listview android-linearlayout