2

I have a RecyclerView and related Adapter class. And I changed the GridLayoutManager's span count.

    fun switchLayout() {
        if (layoutManager?.spanCount == 1) {
            layoutManager.spanCount = 5
        } else {
            layoutManager?.spanCount = 1
        }

        notifyItemRangeChanged(0, itemCount)
    }

And then some animation comes up like below

enter image description here

It's interesting but I don't need it. So, How can I remove this animation?

박찬준
  • 346
  • 1
  • 7

1 Answers1

2

instead of notifyItemRangeChanged(0, itemCount) just use notifyDataSetChanged() - first one is causing animations, second one will force-redraw whole grid from scratch (without respecting previous positions of items, thus moving animations)

for disabling all animations (for adding new item, removing, changing positions/order of 2 or more) you can use recyclerView.setItemAnimator(null) (like comment under question pointing out). then you can still use all notifyItem... methods, changes won't be animated.

or you can also define own custom ItemAnimator with disabled some of animations. e.g. in your case: animateChange should contain line dispatchAnimationFinished(viewHolder) and then return false. in HERE some nice template to use. your class may extends DefaultItemAnimator and then you may override only methods/animations which you want to disable/change

snachmsm
  • 17,866
  • 3
  • 32
  • 74