0

I am using 2 recyclerviews inside nestedscrollview, but after items loaded, app is very slow. it's not scrolling smooth I tried to optimize images and views, but it didn't help at all.

<androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="@color/md_grey_100"
            android:clickable="true"
            android:fillViewport="true"
            android:focusable="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@id/layout_toolbar">

            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                      <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_service_types"
                    android:layout_width="match_parent"
                    android:layout_height="42dp"
                    android:layout_marginTop="8dp"
                    android:nestedScrollingEnabled="false" />
                    
                          <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_stores"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="8dp"
                    android:nestedScrollingEnabled="false" />

    </androidx.appcompat.widget.LinearLayoutCompat>
    
     </androidx.core.widget.NestedScrollView>
1
  • RecyclerView won't recycle views if it's inside in NestedScrollView Commented Dec 24, 2021 at 22:50

1 Answer 1

1

You should avoid using RecyclerView inside NestedScrollView if you have big number of items in RecyclerView If it's items consist images from online, it's causing much laggings and delays Instead using different RecyclerViews, try to use one. In this case, you should define different viewtypes for Adapter.

class YourAdapter(){
override fun getItemViewType(position: Int): Int {
    return when (position) {
       x-> xx
       y-> yy
    }
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    return when (viewType) {
        xx-> YourFirstViewHolder
        yy ->YourSecondViewHolder
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.