Codist
Codist

Reputation: 769

RecyclerView not working inside a ScrollView properly

My app and the RecyclerView was working fine until I add the second RecyclerView on to the fragment. Since I added the second fragment, I added a ScrollView to the fragment. Then I faced some issue with the scrolling within the recyclerview, it didn't scroll smoothly. After going through a lot of articles online including StackOverflow, I changed the ScrollView with androidx.core.widget.NestedScrollView. This fixed the issue with scrolling but some major issue occured. The loading of items in the RecyclerView took more time, when I hit the searchbutton, that's there on the menu bar at the top, it took long time to expand the search field and some times app show 'not responding' message. Some articles say add .setNestedScrollingEnabled=false and I added it like the following in onCreateView() of the fragment. But I am still facing the issue.

I am using kotlin

binding.rv_home_items.isNestedScrollingEnabled=false
binding.rv_home_categories.isNestedScrollingEnabled=false

Following is the xml

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorOffWhite"
        android:orientation="vertical"
        tools:context=".ui.fragments.HomeFragment">
    
        <FrameLayout
            android:id="@+id/framelayout_category"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv_home_categories"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:orientation="horizontal"
                android:paddingBottom="15dp" />
    
            <ImageButton
                android:id="@+id/ibutton_show_category"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:layout_margin="5dp"
                android:background="@drawable/ic_show_category" />
    
        </FrameLayout>
    
        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/framelayout_category">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <com.denzcoskun.imageslider.ImageSlider
                    android:id="@+id/image_slider"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:visibility="gone"
                    app:iss_auto_cycle="true"
                    app:iss_corner_radius="5"
                    app:iss_delay="0"
                    app:iss_error_image="@color/colorDarkGrey"
                    app:iss_period="2500"
                    app:iss_placeholder="@color/colorDarkGrey"
                    app:iss_selected_dot="@drawable/default_selected_dot"
                    app:iss_unselected_dot="@drawable/default_unselected_dot"
                    tools:visibility="visible" />
    
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rv_home_items"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/image_slider"
                    android:layout_marginBottom="50dp" />
            </RelativeLayout>

        </androidx.core.widget.NestedScrollView>
    
    </RelativeLayout>

I am completely stuck on my project, any help with this is highly appreciated

Edit:

When I launch the app, in a few seconds it's shows a message that the app is not responding.

Upvotes: 0

Views: 1077

Answers (1)

Putra Nugraha
Putra Nugraha

Reputation: 624

If you have more than one RecyclerView and even all of them have same scroll direction, seems ConcatAdapter can be preferred solution.

ConcatAdapter enables sequentially combine multiple adapters to a single RecyclerView.

Upvotes: 1

Related Questions