我有一个 ListView,我在其中添加了一个标题。 header 包含另一个 ListView。我希望 header 中的 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>
但我得到一个列表,其中包含一个高度较小的列表的标题。我希望标题中的列表随内容一起增长。
最佳答案
如果您希望您的列表随其内容一起增长,请不要使用 ListView。使用即 LinearLayout 并向其添加元素。
也可以尝试给上面的ListView一个固定的高度(即100dip),让下面的ListView占据剩下的空间。
您还必须知道 layout_heigth 参数与其他小部件/布局相比的工作方式不同。 IE。 wrap_content 没有意义,因为 ListView 可以显示数千个项目并且会占用整个内存。
如果你想使用 ListViews 你应该看过 google io session world of listview作者:罗曼盖伊。
关于android - 如何使 ListView 增长而不是滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6596262/