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:


profile card
Wajahat Karim
🌍 Making the world a better place, one app at a time.
🔥 Google Developer Expert (GDE) in Android . 📱 Professional Android Developer with ~10 years experience. 💻 Creator of various Open Source libraries on Android . 📝 Author of two technical books and 100+ articles on Android. 🎤 A passionate Public Speaker giving talks all over the world.
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