RecyclerView heavy lag with large list

Related searches

I am facing a heavy scroll lag on recyclerview when there are more than 50 items in the adapter. The fragment is skipping frames and the UI/UX is heavily affected. I am populating the list dynamically from the web as lazy loading.

See the problem

I have the following configuration of the recyclerview:

    myRecyclerView=getActivity().findViewById(R.id.myRecyclerView);
    myListAdapter.setHasStableIds(true);
    myListAdapter=new myListAdapter(myRecyclerView,getContext(),R.id.webMRFrame);
    myRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    myRecyclerView.setHasFixedSize(false);

    myRecyclerView.setItemViewCacheSize(200);
    myRecyclerView.setDrawingCacheEnabled(true);
    myRecyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    myRecyclerView.setNestedScrollingEnabled(false);
    myRecyclerView.setAdapter(myListAdapter);

RecyclerView layout:

<LinearLayout 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_height="match_parent"
android:layout_width="match_parent">

<FrameLayout
android:id="@+id/myFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bittentech.hindinews.Fragments.HomeFragment">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/mySwipeRefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/myNestedScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="true"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <!-- TODO: Update blank fragment layout -->
            <android.support.v7.widget.RecyclerView
                android:id="@+id/myRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <ProgressBar
                android:id="@+id/myProgress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/myRecyclerView" />


        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>



</FrameLayout>

</LinearLayout>

My Viewholder item:

<?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"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/myCardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/dimen_8x"
            android:orientation="vertical">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="@dimen/dimen_8x"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/myImage"
                    android:layout_width="150dp"
                    android:layout_height="100dp"
                    app:srcCompat="@mipmap/ic_launcher" />

                <TextView
                    android:id="@+id/myTitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="@dimen/dimen_8x"
                    android:fontFamily="sans-serif-condensed"
                    android:includeFontPadding="false"
                    android:text="Sample Title"
                    android:textColor="@color/defaultContentColor"
                    android:textSize="18dp" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dimen_4x"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/mySource"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/dimen_8x"
                    android:textColor="@color/colorPrimaryDark" />

                <TextView
                    android:id="@+id/myDate"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"

                    android:layout_weight="1"
                    android:textSize="@dimen/dimen_12x" />

            </LinearLayout>

        </LinearLayout>

    </android.support.v7.widget.CardView>

    <View
        android:layout_below="@id/myCardView"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/black"/>
</RelativeLayout>

when you put the Recyclerview inside NestedScrollView the OnBindViewHolder method of the RecyclerAdapter call for each item and bind all the elements at once, which is an expensive task. So if you don't need the functionality of NestedScrollView, then remove it and use RecyclerView as the direct child of SwipeRefreshLayout.

Improve RecyclerView Performance, override fun getItemId(position: Int): Long { in my case, my list scrolled with a bad lag especially on Samsung devices. so try to find other solutions besides these helpful methods. It's very heavy to inflating and binding views. Here we have a vertical RecyclerView with some Horizontal list in each item. The RecyclerView will be a list of randomly chosen movies and a description. We need a class that represents a single RecyclerView item data, create a file named Data.java and add the following:

remove these lines:

myRecyclerView.setItemViewCacheSize(200);
myRecyclerView.setDrawingCacheEnabled(true);
myRecyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

Slow rendering, But this comes with a big downside – if it's a trivial change (maybe a single item added to the top), the RecyclerView isn't aware� These methods help you to improve your RecyclerView performance and maybe they could solve your all problems but in my case, my list scrolled with a bad lag especially on Samsung devices. so try to find other solutions besides these helpful methods.

Add

            android:nestedScrollingEnabled="true"

to your RecyclerView in XML file

Lagging behavious in recyclerview � Issue #822 � bumptech/glide , images and my list is very huge. so Its lagging when I am scrolling. unnecessarily big (size of the screen) image. match_parent and fixed� Heavy lag in recyclerview when scrolling cached images #3050. bignadad opened this issue Apr 25, 2018 · 4 comments Labels. question stale. Comments. Copy link Quote

Speeding up RecyclerViews, scroll speed of a list of items in a RecyclerView was scrolling very slow. the entire view hierarchy to find out how big each view needs to be. RecyclerView is a UI component which allows us to create scrolling list. It was introduced with the Android Lollipop and it’s a kind of ListView2. If we are able to we should use this one instead of a ListView because it forces us to use more efficient way of implementing a list and separates responsibilities to other classes.

RecyclerView scrollbar with lots of items very slow, calling , So I have a RecyclerView with linearlayout, it has say 5000 items. So if I'm at the top of the list, and I move the scroll bar to the middle of the list to go to pos 2500, This seems to be a severe limitation compared to ListView. A long time ago when i started learning developing apps for android, I started with well- known� How to recover data from a hard drive (stuck heads: buzzing, clicking, etc) - Duration: 10:28. DIY Perks Recommended for you

The expandable RecyclerView allows for multiple children or none, so the children need to be added as a list. You can either add the children directly in the getChildObjectList method we implemented by returning your List of children, or you can add them when we create the list of items by calling setChildObjectList with the list of respective children.