2011-07-06 85 views
1

我有一個ListView,其中我添加了一個標題。該標題包含另一個ListView。我希望頭部中的ListView增長,而不是有限大小的滾動。如何使列表視圖增長而不是滾動?

此我膨脹在頭

<ListView android:id="@+id/songinfo_geninfolist" 
     android:isScrollContainer="false" android:layout_marginLeft="10dip" 
     android:layout_margin="5dip" android:padding="5dip" 
     android:scrollbars="none" 
     android:layout_height="wrap_content" android:layout_width="match_parent"> 
    </ListView> 

和該XML是用於主列表

<ListView android:id="@+id/songinfo_linklist" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_marginTop="10dip" android:layout_margin="5dip" 
    android:layout_height="match_parent" android:layout_width="match_parent"> 
</ListView> 

但我得到含有標題列表一個小高的名單。我希望頭中的列表隨內容一起增長。

回答

1

如果您希望列表隨其內容增長,請不要使用ListView。使用即LinearLayout並添加元素。

您還可以嘗試給上部ListView一個固定的高度(即100dip)並讓底部的ListView佔用剩餘的空間。

另外,您必須知道layout_heigth參數與其他Widgets/Layouts的作用不同。即wrap_content沒有意義,因爲ListView可以顯示數千個項目,並且會佔用整個內存。

如果您想使用ListView,您應該已經看過由romain guy的google io會話world of listview

+0

我可以在運行時更新列表高度嗎? 我需要一個列表視圖,因爲我希望它的項目得到專注和點擊。 – rohit

+0

問題解決了。我根據內容設置高度。 – rohit