4
使用ListAdapter填充ScrollView布局中的LinearLayout
我面临一个非常常见的问题:我布置了一个活动,现在事实证明它应该在其中显示一些项目ScrollView。正常的方式做到这一点是使用现有的ListAdapter,它连接到一个ListView和BOOM我有我的产品清单。 但是您不应该在其中嵌套嵌套ListView,ScrollView因为它会使滚动变得更糟-即使Android Lint也抱怨它。 所以这是我的问题: 如何将a连接ListAdapter到a LinearLayout或类似的东西? 我知道此解决方案无法扩展很多项目,但是我的列表很短(<10个项目),因此实际上不需要重用视图。在性能方面,我可以将所有视图直接放入LinearLayout。 我想到的一种解决方案是将现有的活动布局放在的headerView部分中ListView。但这感觉就像在滥用这种机制,因此我正在寻找更清洁的解决方案。 有想法吗? 更新:为了激发正确的方向,我添加了一个示例布局来展示我的问题: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/news_detail_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:visibility="visible"> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFF" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:paddingLeft="@dimen/news_detail_layout_side_padding" android:paddingRight="@dimen/news_detail_layout_side_padding" android:paddingTop="@dimen/news_detail_layout_vertical_padding" android:paddingBottom="@dimen/news_detail_layout_vertical_padding" > <TextView android:id="@+id/news_detail_date" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center_horizontal" android:text="LALALA" android:textSize="@dimen/news_detail_date_height" android:textColor="@color/font_black" /> <Gallery android:id="@+id/news_detail_image" android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingTop="5dip" android:paddingBottom="5dip" /> …