RecyclerView Scrolling Issue with NestedScrollView

Although RecyclerView has a very good and smooth scrolling built-in, but when you put into any ScrollView, then your RecyclerView’s scrolling will not work. For example,

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/listRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="@dimen/_10sdp"
            tools:listitem="@layout/activity_type_item_layout"/>

    </LinearLayout>

</ScrollView>

Now, the RecyclerView will not scroll. To fix that, you will have to use NestedScrollView instead of ScrollView like this:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/listRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="@dimen/_10sdp"
            tools:listitem="@layout/activity_type_item_layout"/>

    </LinearLayout>

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

Now, the RecyclerView will scroll but it will not be smooth. It will stop as soon as finger is off the screen resulting in a very stucking scrolling. To fix this issue, all you have to do is add this line after RecyclerViews adapter has been set.

ViewCompat.setNestedScrollingEnabled(listRecyclerView, false);

Now, your RecyclerView will work with smooth scrolling. This same technique can be used in ViewPager when each Fragment have RecyclerView and the ViewPager is inside any CollapsingToolbarLayout.


If you liked this article, you can read my new articles below:


Wajahat Karim is Pakistan’s first Google Developer Expert in Android. As an experience Android developer, he deeply cares about it and keeps writing and speaking about it. He has written two worldwide 300+ pages books on Android development with more than 100 articles around the internet either on his website or his Medium publications. He is also a passionate contributor in open source and has created many Android libraries used by thousands of developers in their apps worldwide. As active public speaker, he spends lots of time giving talks in conferences and motivating people on Android development. You can find Wajahat most active on Twitter @WajahatKarim where he regularly shares all the good stuff about Android and community building.

Author's picture

Wajahat Karim

🔥 Google Dev Expert (GDE) in Android .
📱 Android Dev. 💻 Open Source Contributor . 📝 Technical Writer . 🎤 Public Speaker

Senior Android Developer

Karachi, Pakistan