android开发过程中,会遇到RecyclerView的做局部item刷新操作时候,出现了闪动问题.
解决方式一:
mCountDownAdapter = new CountDownAdapter(this, mTimeDownBeanList);
recycleView.setHasFixedSize(true);
recycleView.setLayoutManager(new LinearLayoutManager(this));
recycleView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
((SimpleItemAnimator) recycleView.getItemAnimator()).setSupportsChangeAnimations(false);
recycleView.setAdapter(mCountDownAdapter);
recycleView.setHasFixedSize(true);
((SimpleItemAnimator) recycleView.getItemAnimator()).setSupportsChangeAnimations(false);
这两个代码需要添加
解决方式二:
同上述类似
adapter = activity?.let { SteamChargeAdapter(it) }!!
recycleView.setHasFixedSize(true)
adapter.setHasStableIds(true)
recycleView.layoutManager = gridLayoutManager
(recycleView.itemAnimator as SimpleItemAnimator?)!!.supportsChangeAnimations = false
在RecyclerView适配器中重写这个方法:
@Override
public long getItemId(int position) {
return position;
}
以上两种都可以解决,参照代码修改就可以了