The Wayback Machine - https://web.archive.org/web/20240930174707/https://www.geeksforgeeks.org/how-to-improve-recyclerview-scrolling-performance-in-android/
Open In App

How to Improve RecyclerView Scrolling Performance in Android?

Last Updated : 21 Dec, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

RecyclerView is the main UI component in Android which is used to represent the huge list of data. If the RecyclerView is not implemented properly then it will not smoothly scrollable and it may lead to a bad user experience. To make it scrollable smoothly we have to optimize it and follow some tips to improve its performance. In this article, we will see the steps to follow for optimizing the Scrolling performance of our RecyclerView.  

Note:

If you are looking for the implementation guide of RecyclerView. Then do check out: How to implement RecyclerView in Android

1. Set a specific width and height to ImageView in RecyclerView items

In RecyclerView if you’re using ImageView to display an image from your server in your RecyclerView items then specify the constant size for your ImageView. If the size of ImageView in RecyclerView items is not fixed then RecyclerView will take some time to load and adjust the RecyclerView item size according to the size of Image. So to improve the performance of our RecyclerView we should keep the size of our ImageView to make it RecyclerView load faster. 

2. Avoid using NestedView

While creating an item for RecyclerView avoid using NestedView for RecyclerView item. Nesting will reduce the performance of RecyclerView. So it is better to avoid using Nested View. Nested View means adding a Horizontal RecyclerView in a Vertical RecyclerView. This type of Nesting may reduce RecyclerView performance. Below is the image of Nested RecyclerView. 

3. Use the setHasFixedsize method

If the height of our RecyclerView items is fixed then we should use the setHasFixedsize method in our XML of our card item. This will fix the height of our RecyclerView item and prevent it from increasing or decreasing the size of our Card Layout. We can use this method in our JAVA class as well where we are declaring our RecyclerView adapter and layout manager.

recyclerView.setHasFixedSize(true)

4. Use the image loading library for loading images

RecyclerView is composed of so many images and if you are loading an image in all cards then loading each image from the server will take so much time. As the Garbage Collection runs on the main thread so this is the reason which results in unresponsive UI. Continuous allocation and deallocation of memory lead to the frequent GC run. This can be prevented by using the bitmap pool concept. The simple solution to tackle this problem is to use Image Loading libraries such as Picasso, Glide, Fresco, and many more. These libraries will handle all bitmap pool concept and all delegate tasks related to images. 

Note: You may also refer to the Top 5 Image Loading Libraries in Android

5. Do less work in the OnBindViewHolder method

OnBindViewHolder method is used to set data in each item of RecyclerView. This method will set the data in each RecyclerView item. We should do less work in this method. We only have to set data in this method and not to do any comparison or any heavy task. If we perform any heavy task in this method then this will degrade the performance of our RecyclerView because setting data for each item will take a specific amount of time. So to improve the performance of RecyclerView we should do less work in the OnBindViewHolder method.

6. Use the NotifyItem method for your RecyclerView

Whenever you are performing actions in RecyclerView such as adding an item in RecyclerView at any position or deleting an item from a specific position of RecyclerView then you should use NotifyItemChange() method. 

Java




// below method will notify the adapter 
// of our RecyclerView when an item 
// from RecyclerView is removed. 
adapter.notifyItemRemoved(position)
    
// below method will be used when
// we update the data of any RecyclerView 
// item at a fixed position.  
adapter.notifyItemChanged(position)
    
// below method is used when we add 
// any item at a specific position
// of our RecyclerView.  
adapter.notifyItemInserted(position)
    
// below method is used when we add multiple 
// number of items in our recyclerview.
// start represents the position from 
// which the items are added.
// end represents the position upto 
// which we have to add items.   
adapter.notifyItemRangeInserted(start, end)


When we will call the notifyDataSetChanged() method it will not handle the complete reordering of the RecyclerView adapter but it will find if the item at that position is the same as before to do less work. 



Similar Reads

How to Improve RecyclerView Performance in Android Using DiffUtil?
DiffUtil class is used to improve the performance of RecyclerView. The algorithm behind DiffUtil is that it takes two lists and finds differences between the two and provides the updated list as an output. It uses Eugene W. Myers’s difference algorithm to calculate the minimal number of updates. In this article, we will see its implementations. Not
6 min read
How to Disable RecyclerView Scrolling in Android?
RecyclerView is a view group used for displaying data from arrays and databases. RecyclerView basically is a list of items from the data. RecyclerView is often referred to as a successor of GridView and ListView. More about RecyclerView could be found at RecyclerView in Android with Example. RecyclerView lets the users scroll up and down and left a
3 min read
Improve Android App Performance with Benchmarking
Aside from device hardware, the performance of an Android application is also determined by the algorithm that you have used in your application. The selection of the appropriate algorithm and data structures should always be your top priority. These are micro-optimizations that can be made in your app using these changes. So, in order to ensure th
10 min read
How to Disable GridView Scrolling in Android?
A GridView is a ViewGroup that can display data from a list of objects or databases in a grid-like structure consisting of rows and columns. Grid view requires an adapter to fetch data from the resources. This view can be scrolled both horizontally and vertically. The scrolling ability of the GridView by default is set to enabled. However, in this
4 min read
Nested Scrolling in Android using Jetpack Compose
In Android, the Scrollable Modifier detects the scroll gestures but does not offset its contents. Jetpack Compose supports nested scrolling, in which multiple elements react to a single scroll gesture. A typical example of nested scrolling is a list inside another list. [video loading="lazy" mp4="https://media.geeksforgeeks.org/wp-content/uploads/2
2 min read
How to Add Fade and Shrink Animation in RecyclerView in Android?
In this article, we are going to show the fade and shrink animation in RecyclerView. When we move downward then the item at the top will be fading out and then it will shrink. In the output, we can see how it is happening. We will be implementing this Java programming language. [video mp4="https://media.geeksforgeeks.org/wp-content/uploads/20210403
3 min read
Expandable RecyclerView in Android with Kotlin
In this article, we will get to know how to implement the expandable RecyclerView. In General, we will show the list of items in the listview but in some situations like if you want to show the sub-list items, then we have to use an expandable list. See the below image for a better understanding. Step by Step Implementation 1. If you observe the ab
7 min read
Create Floating Animation for RecyclerView Items in Android
In Android, a RecyclerView is a UI element that is used to display a type of layout items in the form of a list. This list is scrollable and each element of the list is clickable. You can find more information on creating RecyclerView in this article: RecyclerView in Android with Example. RecyclerView by default has no entry or exit animation. Howe
5 min read
Android - RecyclerView as Staggered Grid with Kotlin
Staggered Grid View has been seen in most applications such as Pinterest in which each item of grid view takes its own height and aligns within the grid view according to that. In this article, we will look at how to implement Staggered Grid Layout Manager to our Recycler View in Android. Note: If you are looking to implement Staggered Grid Layout
5 min read
How to Implement RecyclerView in a Fragment in Android?
In Android, a fragment is a modular section of a user interface that can be combined with other fragments to create a flexible and responsive application. A fragment represents a behavior or a portion of the user interface in an Activity, which can be reused in different activities or layouts. It has its own lifecycle and can receive input events a
12 min read
RecyclerView using GridLayoutManager in Android With Example
RecyclerView is the improvised version of a ListView in Android. It was first introduced in Marshmallow. Recycler view in Android is the class that extends ViewGroup and implements Scrolling Interface. It can be used either in the form of ListView or in the form of Grid View. How to use RecyclerView as GridView? While implementing Recycler view in
6 min read
CardView using RecyclerView in Android with Example
RecyclerView is an extended version of ListView and GridView. It works on the ViewHolder design pattern. With the help of RecyclerView, we can add many extra features to our list of data. Before starting our example on the implementation of CardView in RecyclerView. We should know what CardView and RecyclerView mean. CardView: CardView is an extend
9 min read
Android Pull to Refresh with RecyclerView in Kotlin
Pull to Refresh is used to update the data within the list in our android application. For implementing this we have to use Swipe to Refresh Layout. Using this widget when the user swipes down the list which is being displayed on the screen is updated. In this article, we will be building a simple application in which we will be displaying a list v
6 min read
Content Placeholder Animation using Shimmer in Android with RecyclerView
We have seen the implementation of Content Placeholder Animation using Shimmer in Android for a simple view. In this article, we will take a look at implementing Content Placeholder Animation using Shimmer in Android with RecyclerView. What we are going to build in this article? We will be building a simple application in which we will be simply di
8 min read
How to Use View Binding in RecyclerView Adapter Class in Android?
View Binding is a part of Android Jetpack which provides the views to bind with the classes by replacing the findViewById() method in a null safe way. In this article, we will see its implementations in the Adapter class of RecyclerView. Note that we are going to implement this project using the Kotlin language. Step by Step Implementation Step 1:
5 min read
Endless RecyclerView in Android
In this article, we are going to see how to build an endless RecyclerView in Android Studio. It is mostly used to design the user interface with great control over the lists and grids of android applications. We can implement both horizontal and vertical layouts using RecyclerView. Here, we will be creating a RecyclerView with a load more option. A
6 min read
How to Create a Collapsing ToolBar and FAB on Scroll with RecyclerView in Android?
In this article, we are going to create a collapsing Toolbar and Floating action button (FAB) on scroll with RecyclerView. Many popular apps have this effect eg. LinkedIn. Below is the sample video to show what we are going to build. Note that we are going to implement this project using the Kotlin language. [video mp4="https://media.geeksforgeeks.
5 min read
Android - How to Change the Color of Alternate Rows in RecyclerView
RecyclerView is an essential ViewGroup used in Android to display a list of items. It provides a flexible and highly customizable way of implementing a list that can be presented as a grid or a list. In this project, we will be working with RecyclerView to change the color of alternate rows. Typically, all items in a RecyclerView have the same colo
10 min read
How to Delete Multiple RecyclerView Items in Android?
RecyclerView is an advanced version of ListView with improved performance. When you have a long list of items to show you can use RecyclerView. It has the ability to reuse its views. In RecyclerView when the View goes out of the screen or is not visible to the user it won’t destroy it, it will reuse these views. This feature helps in reducing power
8 min read
RecyclerView Multiple View Types in Android with Example
We've all used RecyclerView in Android to display a list in our applications. RecyclerView is used to display emails in the Gmail app, feeds on Facebook and Instagram, and messages in WhatsApp, among other things. However, as being an Android Developer you would have come across a fact that when we define a view and the list items are only displaye
4 min read
How to Select Single RadioButton in Android RecyclerView?
RecyclerView is a ViewGroup added to the android studio as a successor of the GridView and ListView. It is an improvement on both of them and can be found in the latest v-7 support packages. It has been created to make possible the construction of any lists with XML layouts as an item that can be customized vastly while improving the efficiency of
4 min read
How to Display Data in Tabular Form using Android RecyclerView?
RecyclerView is a ViewGroup added to the android studio as a successor of the GridView and ListView. It is an improvement on both of them and can be found in the latest v-7 support packages. It has been created to make possible the construction of any lists with XML layouts as an item that can be customized vastly while improving the efficiency of
7 min read
Kotlin Lambda Functions For RecyclerView Adapter Callbacks in Android
Are you using old lengthy java fashioned way of creating & handling callbacks in Android with Interfaces? If yes then it's a very good time to switch on Kotlin Lambda Functions or Higher Order Functions to create & handle callbacks. It's a much short, simpler & easy way. Let's first quickly have a look at older java style way Remember w
4 min read
Android - SearchView with RecyclerView using Kotlin
Many apps display vast amounts of data within their in the form of a list and the user is not able to go through each item within the list to get the item that he wants. For filtering these lists within the android application we can use SearchView to filter it. In this article, we will be building a simple application in which we will be implement
7 min read
Android - RecyclerView using GridLayoutManager with Kotlin
RecyclerView is an improved version of List View in which we can add customization to each item of our recycler view according to our requirements. We can change the orientation of our recycler view depending on our requirements. We can create a simple grid layout, vertical and horizontal recycler view, and a staggered grid view. In this article, w
5 min read
Android - Swipe to Delete and Undo in RecyclerView with Kotlin
We have seen many android applications in which data is being displayed in the form of a list. If we want to delete any item from that recycler view we can simply swipe that item to delete it. We can see this type of feature in the Gmail application in which when an email is swiped to the right it is moved to the archive. In this article, we will b
7 min read
How to Update RecyclerView Adapter Data in Android?
RecyclerView is used in many android applications to display the list of data within android applications. We can dynamically add or remove data from our recycler view. For updating data in the RecyclerView, we have to use the Adapter class. Adapter handles all the data within our recycler view. In this article, we will take a look at How to Update
7 min read
Android - Difference Between RecyclerView and ListView
In Android View is a basic building block of UI (User Interface). A view is a small rectangular box that responds to user inputs. RecyclerView and ListView are the two major Views in Android. So in this article, we are going to see the major differences between these two views. RecyclerView RecyclerView is a ViewGroup added to the android studio as
3 min read
How to Add Drag And Drop Feature in Android RecyclerView?
Drag And Drop feature is very helpful. It is very simple and easy to implement. It is used in many apps that are famous, and if we're doing some project it is very convenient to implement it. You should know the RecyclerAdapter Class. A sample video is given below to get an idea about what we are going to do in this article. [video mp4="https://med
4 min read
How to Animate RecyclerView Items in Android?
RecyclerView Item animation is one of the modern features that we can add to our Android app, the basic working of this is when any user opens our app then the data items that are present in recycler view will animate and then it will show to the user.it is so easy to implement also it can enhance the user experience. A sample video is given below
5 min read