Redeem Now
Read More
Read now

How to optimize Recyclerview in Android


RecyclerView is a flexible view for providing a limited window into a large data set. RecyclerView is an evolutionary version of Listview — one of the most important widgets used in Android development. Android apps using Listview for implementing newsfeed or contact lists will likely face performance issues or unnecessary lags when the user scrolls the view fast. But RecyclerView has improved performance, and it provides a fluid scroll experience for the user.

I will give you the information and important rules you should follow and what you should never do when working with RecyclerView:

1. Replace a complex layout (nested views, RelativeLayout) with the new optimized ConstraintLayout.

ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.

2. If possible, make all elements of the RecyclerView with the same height. And add:

3. Use the default RecyclerView drawing cache methods and tweak them according to your case. You don’t need a third party library to do so:

4. If you use many images, make sure their size and compression are optimal. Scaling images may also affect performance. There are two sides to the problem – the source image used and the decoded Bitmap.

5. Make sure onBindViewHolder() is as cheap as possible. You can set OnClickListener once in onCreateViewHolder() and call through an interface a listener outside of the Adapter, passing the clicked item. This way you don’t create extra objects all the time. Also check flags and states, before making any changes to the view here.

6. When data gets changed, try to update only the affected items. For example instead of invalidating the whole data set with notifyDataSetChanged(), when adding/loading more items, just use:

Rely on notifyDataSetChanged() as a last resort.

But if you need to use it, maintain your items with unique ids:

I hope this blog will help you to optimize the recycleview in your application.

. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again