How to implement ItemAnimator of RecyclerView to disable the animation of notifyItemChanged

前端 未结 8 1125
有刺的猬
有刺的猬 2020-12-13 03:20

In my project I need disable the \"change\" animation of RecyclerView while notifyItemChanged.

I investigated in the source of Recycl

相关标签:
8条回答
  • 2020-12-13 04:16

    I have found the correct solution to just remove the animateChange.

    It's very simple. Google has implemented the functionality.

    ((SimpleItemAnimator) RecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    

    Documentation: setSupportsChangeAnimations

    0 讨论(0)
  • 2020-12-13 04:16

    @Kenny answer didn't work anymore because google remove method setSupportsChangeAnimations() (but why?) in support library 23.1.0.

    In some case setChangeDuration(0) can work as workaround.

    @edit I suggest use something like that:

      RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
            if (animator instanceof SimpleItemAnimator) {
                ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
            }
    
    0 讨论(0)
提交回复
热议问题