Search code examples
androidandroid-recyclerviewmaterial-components-androidandroid-appbarlayout

AppBarLayout does not collapse/expand when scrolling vertically over horizontal RecyclerView inside vertical RecyclerView


When vertical RecyclerView has a horizontal RecyclerView and if user starts scrolling vertically with finger on horizontal RecyclerView then AppBarLayout does not move at all. If finger was on other list items then AppBarLayout does change its state.

Code of CollapsibleToolbar is taken from this article.

The problem is still there with CollapsingToolbarLayout inside AppBarLayout.

Is there any problem with my code or is it a library bug?

Example

<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>

Solution

  • @potados's answer solves the issue. But doesn't explain why it works.

    I created an issue on GitHub page of material components android with the same question. And I would like to post the answer I've received there.

    try to set nestedScrollEnable of Horizontal RecyclerView to false

    If NestedScrollingChild as a child View is enabled, NestedScrollingParent as a parent layout will not intercept scrolling events