Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NestedScrolling with NestedScrollView, RecyclerView (Horizontal), inside a CoordinatorLayout

I have a UI design with CollapsingToolbarLayout, like following.

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout

        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:theme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="24dp">

        <!-- Hiding unrelated code -->

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/card_margin"
            android:padding="16dp">


                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recycler_movie_suggestion"
                    android:layout_width="match_parent"
                    android:layout_height="170dp"
                    android:fillViewport="true"
                    android:nestedScrollingEnabled="false"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

            </LinearLayout>

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

    </LinearLayout>

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

My problem is, the scrolling is fine ONLY when I touch and scroll the area OUTSIDE the RecyclerView. If I try to scroll vertically inside the RecyclerView, the scrolling is "trapped" and ONLY the NestedScrollView is scrolling, the CollaspingToolbarLayout ISN'T collasping.

like image 950
Fung LAM Avatar asked Sep 08 '15 01:09

Fung LAM


People also ask

How can show all items in RecyclerView without scrolling?

How can show all items in RecyclerView without scrolling? In RecyclerView use android:nestedSrollingEnabled="false" and use NestedScrollView as a parent Scroll View.

What is nested scrolling in RecyclerView?

A android.view.ViewGroup that shows items in a horizontal scrolling list. NestedScrollView. NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android.

How do I stop NestedScrollView scrolling?

setnestedscrollingenabled set it to false. try this one add property in recyclerview android:descendantFocusability="blocksDescendants" .

Why we use nested scroll view?

NestedScrollView is used when there is a need for a scrolling view inside another scrolling view.


1 Answers

You need to disable nested scrolling programatically. It doesn't seem to work correctly if done in xml.

recyclerView.setNestedScrollingEnabled(false);
like image 164
tachyonflux Avatar answered Oct 23 '22 17:10

tachyonflux