39

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.

d84619
  • 393
  • 1
  • 3
  • 4

3 Answers3

91

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());
Matthew Shearer
  • 2,715
  • 3
  • 23
  • 32
6

You can also do it with Data Binding in your xml layout file like this:

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:itemAnimator="@{null}" />

This is possible simply because RecyclerView has a public function called setItemAnimator!

Chrisser000
  • 71
  • 2
  • 2
0

I'm using ListAdapter and Matthew's solution did not work for me, when I re-enable animation it active animation back. I use this if anybody else needed (Kotlin):

recyclerView.itemAnimator = null
adapter.submitList(items.toList()){
    recyclerView.itemAnimator = DefaultItemAnimator()
}
Javad
  • 361
  • 5
  • 9
  • 1
    SubmitList is asynchronous. You can pass function argument as last parameter and it'll be triggered when list is submitted: adapter.submitList(items.toList()) { recyclerView.itemAnimator = DefaultItemAnimator() } – BochenChleba Mar 02 '23 at 22:06
  • Thanks @BochenChleba, it's a significantly better solution, I will edit the answer – Javad Mar 09 '23 at 18:51