Nested RecyclerView with CoordinatorLayout

Rafique Mohammed picture Rafique Mohammed · Jan 14, 2016 · Viewed 15.9k times · Source

My question is just like this question Scroll behavior in nested RecyclerView with horizontal scroll

Just like Google Play store, I have a nested RecyclerView(Horizontal) inside a parent RecyclerView. The parent RecyclerView is a child of CoordinatorLayout in which the toolbar expands and collapse when the parent RecyclerView scrolling happens.

Everything works fine on touch outside of the child RecyclerView and scroll up CollapsingToolbar get collapsed but when i touch one of the the child RecyclerView and scroll up then the parent RecyclerView get scrolled and CollapsingToolbar doesn't work.

enter image description here

enter image description here

If require then i will add my Source Code here..

Any help will be appreciated!!

UPDATE :

activity of CoordinatorLayout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coord_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.ChannelHubOld">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="?attr/colorPrimary"
        android:fitsSystemWindows="true">
        <RelativeLayout
            android:background="@color/pkDarkGrey"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="200dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/sidebar_header"/>
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:theme="@style/ActionBarWidget"/>

    </android.support.design.widget.CollapsingToolbarLayout>

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

<!-- Parent RecyclerView --->

    <android.support.v7.widget.RecyclerView
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycler_view_pagelayout"
        />

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

Answer

fast3r picture fast3r · Feb 5, 2016

Had the same issue. Fixed by setting setNestedScrollingEnabled(false) on the horizontal nested RecyclerViews. It seems like the nested scroll wasn't intercepted properly by the CoordinatorLayout.Behavior when not setting this. Try it out!


NOTE: you also have to add a layout behavior (example: app:layout_behavior="@string/appbar_scrolling_view_behavior" ) to the inner (nested) RecyclerView for this to work