Learn Pain Less

HomeOur TeamContact
Android
How to fix blinking issue for RecyclerView notify changes
Pawneshwer Gupta
Pawneshwer Gupta
June 06, 2018
1 min
How to fix blinking issue for RecyclerView notify changes

How to fix blinking issue for RecyclerView notify changes

If you are Android developer then you surely use RecyclerView to show list of items to users. And you also developed such apps which requires data changes frequently in RecyclerView. And you may noticed that whenever you use adapter. NotifyDataSetChanged(), adapter.notifyItemChanged(int position) etc methods then your RecyclerView blink for few nanoseconds. And it looks like that your app is blinking due to lag. Actually this is due to Animation in RecyclerView. As stated in official documentation of RecyclerView that RecyclerView uses DefaltItemAnimator by default. Which means if you doesn’t specify ItemAnimator to RecyclerView then it still got animations.

You can see those animation while removing items or adding new items to RecyclerView. So simple trick is disable animations in RecyclerView item and your problem will be resolved.

Below is code to disable animations in RecyclerView.

SimpleItemAnimator itemAnimator = myRecyclerView.getItemAnimator()
itemAnimator.setSupportsChangeAnimations(false);

OR, in single line

((SimpleItemAnimator) myRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Tags

recyclerviewanimation

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

Multiple selection RecyclerView Android
Multiple selection RecyclerView Android
August 31, 2017
1 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media