How to use vertical RecyclerView inside ScrollView on Android

It was one of my problems, how to design nested vertical RecyclerView inside ScrollView in Android. The answer is:

androidx.core.widget.NestedScrollView

It should be mentioned that in this case, the RecyclerView is NOT the RecyclerView anymore!

In the first step, you need to create NestedScrollView element in XML:

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

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

// RecyclerViews should be located here

</LinearLayout>
</androidx.core.widget.NestedScrollView>

Next, add the below attribute to recyclerView:

android:overScrollMode="never"

Then, the recyclerView will be as following:

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />

Finally, the whole the layout will be something like below, you can add other materials inside LinearLayout:

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />
// other materials </LinearLayout>
</androidx.core.widget.NestedScrollView>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arman Kolahan

Arman Kolahan

109 Followers

I am an android and web developer, mainly working on Kotlin, JavaScript, PHP, and Java.