Recyclerview notifyItemChanged 刷新item閃爍

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

 這個方法僅影響itemchange,並不會影響列表添加的動畫 

 /**
     * 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(RecyclerView.ViewHolder, RecyclerView.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(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int,
     *                                 int)} when changes occur.
     * @see RecyclerView.Adapter#notifyItemChanged(int)
     * @see RecyclerView.Adapter#notifyItemRangeChanged(int, int)
     */
    public void setSupportsChangeAnimations(boolean supportsChangeAnimations) {
        mSupportsChangeAnimations = supportsChangeAnimations;
    }

查看Recyclerview 源碼  ItemAnimator 中有定義各種場景的動畫時間

        private long mAddDuration = 120;
        private long mRemoveDuration = 120;
        private long mMoveDuration = 250;
        private long mChangeDuration = 250;

  還可以設置相關時間 

/** * 打開默認局部刷新動畫 / 
public void openDefaultAnimator() { 
this.getItemAnimator().setAddDuration(120); this.getItemAnimator().setChangeDuration(250); this.getItemAnimator().setMoveDuration(250); this.getItemAnimator().setRemoveDuration(120); 
((SimpleItemAnimator) this.getItemAnimator()).setSupportsChangeAnimations(true); 
} 

/* * 關閉默認局部刷新動畫 */
 public void closeDefaultAnimator() { 

this.getItemAnimator().setAddDuration(0); this.getItemAnimator().setChangeDuration(0); this.getItemAnimator().setMoveDuration(0); this.getItemAnimator().setRemoveDuration(0); 
((SimpleItemAnimator) this.getItemAnimator()).setSupportsChangeAnimations(false); }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章