Resolve RecyclerView Blinking (RRB)

The flickering issue you are experiencing after calling notifyItemChanged(pos) in a RecyclerView may be related to the built-in item change animation. By default, RecyclerView applies a fade-in/fade-out animation when an item is changed. If you don't want this animation, you can disable it by using ItemAnimator.

Here's how to prevent the flickering effect:

RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setItemAnimator( null ); // Disable the default item change animation

// Now, when you call notifyItemChanged(pos), it won't have the default fade-in/fade-out animation.

By setting ItemAnimator to null, you effectively disable the default animation for item changes.

Alternatively, if you want to keep some animations but just disable the blinking effect, consider customizing the ItemAnimator itself. For example, you could create a custom ItemAnimator that doesn't include the fade effect:

public  class  NoBlinkItemAnimator extends DefaultItemAnimator {
    @Override
    public boolean animateChange (@NonNull RecyclerView.ViewHolder oldHolder, @NonNull RecyclerView.ViewHolder newHolder, @Nullable ItemHolderInfo preInfo, @Nullable ItemHolderInfo postInfo) {
         // Skip the default animation for item changes 
        dispatchChangeFinished(oldHolder, true );
        dispatchChangeFinished(newHolder, false );
         return  false ;
    }
}


Then, assign your custom ItemAnimator to the RecyclerView:

RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setItemAnimator( new NoBlinkItemAnimator());

This way, you can have more control over the animation effects if you want to keep some animations but remove the flickering behavior.

RecyclerView has built-in animations that usually add a nice subtle effect. In your case, you'll want to disable them:

(mRecyclerView?.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false

Post a Comment

Previous Next

نموذج الاتصال