RecyclerView实现双向滚动

4
如何展示一个非常大的项目列表(横向/纵向),并允许自由滚动/拖动-就像Google表格一样?
我尝试使用带有RecyclerView的NestedScrollView,但是你只能一次在一个方向上滚动,而我需要它能够自由地被拖动(不需要捏/缩放功能,但如果可以做到的话,那是额外的奖励)。
这里是一个GIF,展示了我尝试过的内容,它可以工作,但绝对不是我想要的。

enter image description here

这是布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        layout="@layout/include_toolbar"
        android:id="@+id/toolbar" />

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_biscroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.v4.widget.NestedScrollView>

</LinearLayout>

我认为这个答案可以解决你的问题。 - Lester L.
@LesterL。我已经尝试了ScrollView和NestedScrollView,虽然它们可以工作,但我无法自由地对布局进行“对角线”拖动。 - Alvin Rusli
2个回答

5
我终于得到了答案:使用自定义的LayoutManager实现。
我移除了外部的ScrollView,在我的代码中添加了FixedGridLayoutManager,然后将其用作RecyclerView的布局管理器:
FixedGridLayoutManager layoutManager = new FixedGridLayoutManager();
layoutManager.setTotalColumnCount(adapter.getItemCount()); // This probably needs to update when item count is changed
recyclerView.setLayoutManager(layoutManager);

0
你尝试过将 Recycler View 放在 Scroll View 内部吗?

请查看我提供的布局文件。 - Alvin Rusli

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接