Android 如何将两个listview一起滚动

Android 如何将两个listview一起滚动,android,android-listview,Android,Android Listview,我还没有找到解决这个问题的合适办法。我正在片段中实现列表。我在一个线性布局中有两个列表视图 假设我在列表1中有五项,在列表2中有三项。因此,当用户滚动时,他应该会获得滚动一个列表的体验 到目前为止,列表1和列表2都有各自独立的滚动行为。我的代码在下面 List.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android

我还没有找到解决这个问题的合适办法。我正在片段中实现列表。我在一个
线性布局中有两个
列表视图

假设我在列表1中有五项,在列表2中有三项。因此,当用户滚动时,他应该会获得滚动一个列表的体验

到目前为止,列表1和列表2都有各自独立的滚动行为。我的代码在下面

List.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_gray"
    tools:context=".fragment.MallListFragment"
    android:orientation="vertical">

    <ListView
        android:id="@+id/list1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="2dp"
        android:clipToPadding="false">
    </ListView>

    <ListView
        android:id="@+id/list2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ListView>

</LinearLayout>

使用CWAC MergeAdapter执行此操作的最简单方法-

此库允许您将两个不同的适配器添加到一个-MergeAdapter,并将此MergeAdapter添加到一个Listview

MergeAdapter mergeAdapter = new MergeAdapter();
mergeAdapter.addAdapter(yourFirstAdapter);
mergeAdapter.addAdapter(yourSecondAdapter);
mYourListView.setAdapter(mergeAdapter);

您可以考虑使用一个带有部分标头的ListVIEW。基本上,您可以创建一个自定义适配器,该适配器绑定两个(或更多)适配器,并在适当的时候返回头视图,如前所述。

为什么不使用单一列表?请提供更多信息我不能使用单一列表,因为两个列表中的内容排列不同。在一个列表视图中使用不同的视图,而不是使用两个列表视图。他指的是自定义列表视图。使用自定义列表view@AshwinNarayanan你能提供任何链接吗。谢谢谢谢,还有一件事。我希望第二个适配器中的列表数据不可单击。有什么建议吗。我尝试转到我的xml并将clickable设置为false,但如果在第二个适配器setOnClickListner(null)中的行使用布局(父级)中的setOnItemClickListener(..),则该设置无效;或者在McClickListner中检查大小。