I have two RecyclerView
s in one layout. Until now I can't scroll the page itself, only each RecyclerView
, which feels strange. Now I am trying to figure out the best practive for scrolling a page with two RecyclerView
s. I heard that when I put them in a NestedScrollView
, they stop recycling their views.
- Is is true that putting
RecyclerView
inside aNestedScrollView
disables the recycling of items in theRecyclerView
? - Especially if number 1 is true, what is the current recommended way to enable scrolling for a page with two Recyclerviews?
Update
Here's my layout. Assume that recycler1
and recycler2
don't carry items that are related together, so putting them inside one RecyclerView
(using different view types) feels semantically wrong to me.
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:text="first title"
app:layout_constraintBottom_toTopOf="@+id/recycler1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/text1"
tools:itemCount="3"
tools:listitem="@layout/item_category" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="24dp"
android:text="second title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/recycler1" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/text2"
tools:itemCount="3"
tools:listitem="@layout/item_category" />
</androidx.constraintlayout.widget.ConstraintLayout>