首页 > 解决方案 > 在垂直 RecyclerView 内的水平 RecyclerView 上垂直滚动时,AppBarLayout 不会折叠/展开

问题描述

当垂直 RecyclerView 具有水平 RecyclerView 并且如果用户开始用手指在水平 RecyclerView 上垂直滚动,则 AppBarLayout 根本不会移动。如果手指在其他列表项上,则 AppBarLayout 会更改其状态。

代码CollapsibleToolbar取自这篇文章。

CollapsingToolbarLayoutAppBarLayout 内部的问题仍然存在。

我的代码有问题还是库错误?

例子

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="76dp"
        android:theme="@style/AppTheme.AppBarOverlay.Light">

        <com.example.notcollapsingappbar.CollapsibleToolbar
            android:id="@+id/motion_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="@dimen/actionBarSize"
            app:layoutDescription="@xml/scene_header"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="start|center_vertical"
                android:text="Large title"
                android:textColor="@android:color/white"
                android:textSize="30sp"
                app:autoSizeTextType="uniform" />

        </com.example.notcollapsingappbar.CollapsibleToolbar>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingBottom="16dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

标签: androidandroid-recyclerviewmaterial-components-androidandroid-appbarlayout

解决方案


@potados 的回答解决了这个问题。但没有解释为什么它有效。

我在材料组件 android的GitHub 页面上用同样的问题创建了一个问题。我想发布我在那里收到的答案。

尝试将 Horizo​​ntal RecyclerView 的 nestedScrollEnable 设置为 false

如果启用了作为子View的NestedScrollingChild,作为父布局的NestedScrollingParent将不会拦截滚动事件


推荐阅读