Does
Does

Reputation: 31

recycleview scroll with other view at same time

i have recycleview and in top i have one view which includes textview .

my problem is when scroll up that text-view always at top and only recycle-view scroll .. is any way i can scroll both . i don't want to use view type in recycle-view as it already use for some other purpose

my XML

 <Rel layout>
 <text-view id="text"/>
 <recycle-view below="text" />

so how textview will go up and down with recycle-view scroll can any give small snippet for this

Upvotes: 3

Views: 3245

Answers (1)

ekchang
ekchang

Reputation: 939

If you really want to keep the TextView separate from the RecyclerView, wrap them in a NestedScrollView instead:

<NestedScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
      <TextView />
      <RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
  </LinearLayout>
</NestedScrollView>

When you set up your RecyclerView, you will probably want to call RecyclerView#setNestedScrollingEnabled(false) otherwise the RV may consume some scrolling inside the parent (which you don't want).

NOTE: This approach makes the tradeoff that the RV will be forced to layout all of its views, losing the recycling benefit. The correct approach would be to properly dedicate a viewType to the RV for this header TextView and not deal with wrapping it inside additional ViewGroups.

Upvotes: 6

Related Questions