2011-07-06 79 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