RecyclerView:notifyItemChanged刷新闪烁问题

出处:https://blog.csdn.net/u014537423/article/details/52777978


RecyclerView调用notifyItemChanged闪烁问题相信很多人都遇到过。

那是因为recyclerView默认设置的动画DefaultItemAnimator造成的,

DefaultItemAnimator继承自SimpleItemAnimator,里面有个方法是

/**

    * Sets whether this ItemAnimator supports animations of item change events.

    * If you set this property to false, actions on the data set which change the

    * contents of items will not be animated. What those animations do is left

    * up to the discretion of the ItemAnimator subclass, in its

    * {@link #animateChange(ViewHolder, ViewHolder, int, int, int, int)} implementation.

    * The value of this property is true by default.

    *

    * @param supportsChangeAnimations true if change animations are supported by

    *                                this ItemAnimator, false otherwise. If the property is false,

    *                                the ItemAnimator

    *                                will not receive a call to

    *                                {@link #animateChange(ViewHolder, ViewHolder, int, int, int,

    *                                int)} when changes occur.

    * @see Adapter#notifyItemChanged(int)

    * @see Adapter#notifyItemRangeChanged(int, int)

    */

    public void setSupportsChangeAnimations(boolean supportsChangeAnimations) {

        mSupportsChangeAnimations = supportsChangeAnimations;

    }

只要设置为false,就可以不显示动画了,也就解决了闪烁问题。

代码其实就一句话。

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,129评论 0 10
  •   最近在看别人关于RecyclerView的博客,恰巧看到一位国外大神的博客,是关于RecyclerView动画...
    琼珶和予阅读 4,427评论 0 1
  • 这篇文章分三个部分,简单跟大家讲一下 RecyclerView 的常用方法与奇葩用法;工作原理与ListView比...
    LucasAdam阅读 9,904评论 0 27
  • 《尘埃落定》终于尘埃落定了。 经典回顾: 时间加快,并不是太阳加快了在天上的步伐,要是用日出日落来衡定时间的话,它...
    艾棋儿阅读 4,969评论 0 9
  • 我出轨了。 我喜欢上了一个比我大的妇女。 一开始,只是为了寻找刺激。生活太平淡了,总觉得没什么意思。 我也没想到会...
    金剑书生阅读 1,111评论 0 0