Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recyclerview inside scrollview- How to scroll whole content?

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.

like image 312
Rushikesh Talokar Avatar asked Jan 06 '16 09:01

Rushikesh Talokar


2 Answers

Put the LinearLayout which contains both the static and dynamic data inside of a NestedScrollView and it'll work like a charm.

Here is the code you need:

<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<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>
</android.support.v4.widget.NestedScrollView>

I hope it helps!

like image 194
Farid Arbai Avatar answered Sep 18 '22 10:09

Farid Arbai


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

like image 21
Jignesh Mavani Avatar answered Sep 19 '22 10:09

Jignesh Mavani