Recyclerview inside scrollview- How to scroll whole content?

Rushikesh Talokar picture Rushikesh Talokar · Jan 6, 2016 · Viewed 7.9k times · Source

I am having Recyclerview inside Scrollview

 <Scrollview
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

    <LinearLayout
        android:id="@+id/layoutStaticContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

       //Static content.
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp">
           .
           .
        <LinearLayout>

         //Dynamic content(newsfeed)
         <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>
 </ScrollView>

Now while scrolling, layoutStaticContent stays fix on the top & recyclerview content scrolls independently in the bottom part. How to scroll the whole content i.e (layoutStaticContent + recyclerview content) such that there is only 1 scrollview? I also tried replacing scrollview with Nestedscrollview but no success.

Answer

Jignesh Mavani picture Jignesh Mavani · Jan 6, 2016

Use the android.support.v4.widget.NestedScrollView then inside both layout NestedScrollView