You*_*sef 5 java height android android-layout android-listview
我正在开发一个Android应用程序.
在XML布局中,我需要执行以下操作:
我在顶部有一个列表视图(listViewProducts),下面有另一个相对视图(receiptSection).
列表视图应占用与项目一样多的空间.其余部分由receiptSection拍摄.
例如,如果我在listViewProducts中有2个项目:
列表视图与2个项目一样大,其余部分由receiptView获取.
如果我添加另一个项目,列表视图现在占用更多空间并将receiptView推低:
但是,如果我添加更多项目,我希望列表视图高度停止增长,以留下不能变小的receiptView的最小高度:
如图所示,receiptVIew的最小高度为50dp.一旦收据视图达到该高度,它应该停止收缩,现在列表视图具有基于剩余空间的固定大小.其余的将是可滚动的.
我试过了什么
我创建了一个列表视图.我有android:layout_alignParentTop="true"
和android:layout_height="wrap_content"
.
这将使其内容增长并位于视图的顶部
<ListView
android:id="@+id/listViewProducts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
</ListView>
Run Code Online (Sandbox Code Playgroud)
我创建了一个RelativeLayout,它将保存一个单独的xml布局文件中的checkout_receipt_view.
对于这个观点我已经android:layout_alignParentBottom="true"
和android:layout_below="@id/listViewProducts"
这将使它进入列表视图下,在视图的底部对齐.
我也用android:minHeight="50d"
它来设置receiptSection的最小高度.
<RelativeLayout
android:id="@+id/receiptSection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="@id/listViewProducts"
android:minHeight="50dp" >
<include layout="@layout/checkout_receipt_view" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
listViewProducts随着项目的增长而增长,而receiptView正在正确地占用剩余空间.
然而问题 是最小高度不起作用.列表视图继续无限增长,receiptSection将被推出视图.
当receiptView达到50dp时,有没有办法让listView停止增长?
非常感谢您的帮助.
小智 -1
尝试交换“layout_below”。
您实际上要说的是:请将我的相对布局放在列表视图下方。如果您希望列表视图尊重相对布局的高度,则必须在列表视图中说:
<ListView
android:id="@+id/listViewProducts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/receiptSection"
android:layout_alignParentTop="true" >
</ListView>
Run Code Online (Sandbox Code Playgroud)
和你的相对布局:
<RelativeLayout
android:id="@+id/receiptSection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:minHeight="50dp" >
<include layout="@layout/checkout_receipt_view" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1035 次 |
最近记录: |