Disable animation on notifyItemRangeInserted()

d84619 picture d84619 · Jun 1, 2017 · Viewed 11.9k times · Source

I'm using a RecyclerView. After adding items to the RecyclerView, I need to call:

notifyItemRangeInserted(int positionStart, int itemCount);

However, this shows a sort of "slide down" animation. Is there a way that I can disable this animation?

Thanks.

Answer

Matthew Shearer picture Matthew Shearer · Jun 1, 2017

try clearing the RecyclerView item animator

recyclerView.setItemAnimator(null);

you can re-enable your animation after if needed.

recyclerView.setItemAnimator(null);
notifyItemRangeInserted(int positionStart, int itemCount);
recyclerView.setItemAnimator(new DefaultItemAnimator());