Disable animation on notifyItemRangeInserted()

Viewed 20820

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.

3 Answers

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!

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.postDelayed({
    recyclerView.itemAnimator = DefaultItemAnimator()
}, 120)
Related