notifyItemChanged(pos)后如何防止RecyclerView项目闪烁? [英] How to prevent RecyclerView item from blinking after notifyItemChanged(pos)?

查看:739
本文介绍了notifyItemChanged(pos)后如何防止RecyclerView项目闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个回收站视图,其数据每5秒更新一次.要更新列表中的数据,我正在使用

I currently have a recycler view whose data updates every 5 secs. To update the data on the list, I am using

notifyItemChanged(position);
notifyItemRangeChanged(position, mList.size());

每次调用notifyItemChanged()时,回收台视图上的项目都会正确更新,但是它将闪烁,因为这将导致再次调用onBindViewHolder.因此,好像每次都是新的负载.如果可能的话,如何防止这种情况发生?

Each time I call notifyItemChanged(), the items on my recycler view update properly, however, it will blink because this causes onBindViewHolder to be called again. So it's as though it is a fresh load each time. How can I prevent this from happening, if possible?

推荐答案

RecyclerView具有内置的动画,这些动画通常会添加精美的效果.在您的情况下,您将要禁用它们:

RecyclerView has built in animations which usually add a nice polished effect. in your case you'll want to disable them:

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

(默认的回收者视图动画师应该已经是 SimpleItemAnimator )

(The default recycler view animator should already be an instance of SimpleItemAnimator)

这篇关于notifyItemChanged(pos)后如何防止RecyclerView项目闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆