让自己陷入困境,试图在同一个活动中挤压两个 ListView。它使用包含在标准(垂直)LinearLayout 中的两个单独的 ListFragment 来工作。
问题是,这两个列表加起来比屏幕长,因此第二个列表被部分隐藏了。从视觉上看,用户希望向上拖动整个屏幕并显示第二个列表。但是这两个列表有自己的内部滚动,它们不允许整个屏幕作为一个整体滚动。
幸运的是,这些列表实际上包含的项目很少(平均每个 5 个)。因此,理论上,我可以填充几个 LinearLayouts 容器。问题是,列表显示的数据来自游标并且是动态的。虽然我知道 CursorAdapter 的 newView() 和 bindView() 方法,但我不太明白如何将适配器连接到 LinearLayout 容器而不是 ListViews。即 CursorAdapter 如何知道它必须从它在光标中找到的 5 个项目中创建 5 个行项目?在哪里创建循环遍历光标项并在 LinearLayout 容器中创建项?当 Cursor 中的数据发生变化时,如何刷新 LinearLayout 的内容?我发现的所有示例都将这些问题巧妙地包装到 ListActivity 提供的 ListView 中,
我很困惑!
马努
编辑:这是遵循 breceivemail 建议时 (Fragment)Activity 的 xml 布局。在 breceivemail 的建议之前,注释掉的是原始的 LinearLayout 容器。还应该注意的是,整个活动又包含在 TabHost 中,但我不知道这是否对手头的问题有任何影响。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!--
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
-->
<TextView android:id="@+id/title"
android:textSize="36sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/SelectPlayer"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Playing"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#000000"
android:background="#999999"/>
<fragment android:name="com.myDomain.myApp.PlayerListFragment"
android:id="@+id/playing"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Reserve"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#000000"
android:background="#999999"/>
<fragment android:name="com.myDomain.myApp.PlayerListFragment"
android:id="@+id/reserve"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>