闪动原因:是调用notifyItemChanged方法时传了一个参数,查看源码
//刷新单个item的方法,调用notifyItemRangeChanged
public final void notifyItemChanged(int position) {
this.mObservable.notifyItemRangeChanged(position, 1);
}
//第三个参数为null
//@param payload Optional parameter, use null to identify a "full" update
//如果传入null则全部刷新
public void notifyItemRangeChanged(int positionStart, int itemCount) {
this.notifyItemRangeChanged(positionStart, itemCount, (Object)null);
}
第三个参数为null会导致全部刷新,所以会item会闪动
解决方法:
adapter.notifyItemChanged(position, position);or在adapter里冲下方法notifyItemChanged();
解决原因:
//调用刷新时第二个参数会当做第三个参数传到调用方法里
public final void notifyItemChanged(int position, @Nullable Object payload) {
this.mObservable.notifyItemRangeChanged(position, 1, payload);
}
//这样就值刷新局部了,并不会刷新了
public void notifyItemRangeChanged(int positionStart, int itemCount, @Nullable Object payload) {
for(int i = this.mObservers.size() - 1; i >= 0; --i) {
((RecyclerView.AdapterDataObserver)this.mObservers.get(i)).onItemRangeChanged(positionStart, itemCount, payload);
}
}