0

我有一個帶有LinearLayout的Linear.xml,包含LinearLayout,ListView和LinearLayout中的三個項目。我希望ListView儘可能大,同時保持底部的LinearLayout始終顯示,而不是縮小或關閉屏幕。獲取視圖以適合

我已經嘗試使ListView高度fillparent,但然後底部LinearLayout不顯示,與wrapcontent相同,因爲ListView有很多內容。

當我使ListView成爲設置大小,比如300dp時,我在底部的LinearLayout下面有空間。我試圖通過使頂層LinearLayout gravity = fill來解決這個問題,但這並沒有幫助。

此外,根據android我嘗試它,底部的LinearLayout將從屏幕上退出或收縮。 如果相關,頂層LinearLayout被設置爲fillparent以指示高度。 我的目標是保持頂部和底部的LinearLayout包裝他們的內容,並且中間的ListView填充剩下的東西...任何建議? 在此先感謝您的努力!

回答

3

我相信你可以直接將android:layout_weight="1"添加到ListView中,將ListView設置爲fill_parent的高度,並將兩個LinearLayouts設置爲wrap_content。無論如何,我通常更喜歡使用RelativeLayout。您可以指定頭對準屏幕的頂部,頁腳對齊底部,ListView控件,以填補空間之間,像這樣:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     > 
     //...insert stuff here 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     > 
     //...insert stuff here 
    </LinearLayout> 

    <ListView 
     android:id="@+id/listview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/footer" 
     android:layout_below="@id/header" 
     /> 
</RelativeLayout> 
+0

感謝兩種反應是完美的!並且,學習新視圖很好 – 2011-03-01 06:45:05