1

I have a layout which is like this

TextView 1

TextView 2

TextView 3

ImageView

Recyclerview

[item 1 to 10 organized vertically]

Now, when I am scrolling the page, the entire page must scroll, not the Recyclerview alone. This is a very common and an old thing in android, the solutions I get is implementing the
Is there an addHeaderView equivalent for RecyclerView?

I don't want to follow this approach as it is quite a hacky solution. I feel implementing recyclerview inside nestedscrollview might solve my issue, am I taking the right approach? or should I be using coordinator layout? Any help is highly appreciated, can you also provide me some links that meet my requirements.?

Community
  • 1
  • 1
akash89
  • 881
  • 3
  • 12
  • 31

1 Answers1

3

I found out the solution for this query. Have a look at this layout, The idea is to have a

CoordinatorLayout as the root

--AppBar layout happens to be the direct child layout for Coordinator

Host the relative layout that will have the different textview/radiobutton (that you want to add as a header kind of thing)

---Close the appbarlayout

Add the recyclerview just below the appbarlayout.

It will work fine, check out the layout that I have used and don't forget to add app:behavior in proper places.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                     android:layout_width="match_parent"
                                                     xmlns:app="http://schemas.android.com/apk/res-auto"
                                                     android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent">

        <RelativeLayout
                android:layout_width="match_parent"
                app:layout_scrollFlags="scroll|enterAlways"
                android:layout_height="wrap_content"
                android:id="@+id/relLayout">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="Large Text"
                    android:id="@+id/textView"
                    android:layout_marginLeft="97dp"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginTop="37dp"/>

                <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="New RadioButton"
                        android:id="@+id/radioButton"
                        android:layout_below="@+id/textView"
                        android:layout_alignLeft="@+id/textView"
                        android:layout_marginTop="49dp"/>
            </RelativeLayout>
        </android.support.design.widget.AppBarLayout>

     <android.support.v7.widget.RecyclerView
           app:layout_behavior="@string/appbar_scrolling_view_behavior"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="@dimen/padding_small"
             android:layout_below="@+id/relLayout"
             android:id="@+id/recyclerview_settings_list"
             android:scrollbars="vertical"/>

</android.support.design.widget.CoordinatorLayout>
akash89
  • 881
  • 3
  • 12
  • 31