簡體   English   中英

Android列表視圖將內容包裝到基於頁腳大小的特定大小

[英]Android list view wrap content until a certain size based on footer size

我正在開發一個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>

我創建了一個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>

listViewProducts隨着項目的增長而增長,而receiptView正在正確地占用剩余空間。

然而問題是最小高度不起作用。 列表視圖繼續無限增長,receiptSection將被推出視圖。

當receiptView達到50dp時,有沒有辦法讓listView停止增長?

非常感謝您的幫助。

嘗試交換'layout_below'。

你實際上說的是以下內容:請將我的相對布局放在列表視圖之下。 如果您希望listview尊重relativelayout的高度,您必須在listview中說:

 <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>

你的親戚:

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM