具有水平滚动的嵌套 RecyclerView 中的滚动行为

Scroll behavior in nested RecyclerView with horizontal scroll

我必须在每个项目中创建垂直 RecyclerView 和嵌套水平 RecyclerView。一切都在 CoordinatorLayout 之内。当我通过点击嵌套的 RecyclerView 工具栏外部滚动隐藏时,但是当我通过点击嵌套的一个工具栏滚动父 Recycler 时。

如有任何帮助,我们将不胜感激。

这是我的 xml 布局:

main_activity.xml:

<android.support.design.widget.CoordinatorLayout 
   ...>

<FrameLayout
    android:id="@+id/fragment_frame"
    ...
    android:fitsSystemWindows="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.AppBarLayout
    ...
    android:fitsSystemWindows="true"
    android:id="@+id/appbar_layout">

        <include layout="@layout/toolbar"/>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

这里是 toolbar.xml :

<android.support.v7.widget.Toolbar
    android:id="@+id/main_toolbar"
    ...
    android:fitsSystemWindows="true"
    app:layout_scrollFlags="scroll|enterAlways">

    <TextView .../>

</android.support.v7.widget.Toolbar>

fragment.xml:

<android.support.v7.widget.RecyclerView
    ...
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

和recycler_view_item.xml:

<RelativeLayout ...>

    <TextView .../>

    <!-- fixme(CullyCross) fix bug with hiding toolbar -->
    <android.support.v7.widget.RecyclerView
        ...
        android:scrollbars="horizontal"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

</RelativeLayout>

谢谢,
安东

尝试在 android.support.v4.widget.NestedScrollView 中使用 RecyclerView

<android.support.v4.widget.NestedScrollView
        android:id="@+id/nScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

<!-- Set other views of your Layout -->

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

也尝试在 Toolbar

中使用不同的 layout_scrollFlags
RecylerView.setNestedScrollingEnabled(false); // set it true or false as per requirement

这里所要求的是到目前为止我发现足够好的解决方案:

在我的例子中,我有一个 nestedScrollView,其中 4 个 RecyclerView 设置为在内部水平滚动。对于这些 RecyclerView 中的每一个,我都以编程方式完成了此操作:

restaurantsRecylerView.setHasFixedSize(true); 
restaurantsRecylerView.setNestedScrollingEnabled(false);

您可能不想要 fixedSize,不确定它是否会有所不同,我的列表始终为 25,因此我可以使用它来提高性能。完成此操作后,即使触摸 recyclerViews

,我也可以毫无问题地滚动

希望对您有所帮助

我们可以在 XML

中实现
android:nestedScrollingEnabled="false"