在recyclerview中图像闪烁的Android图像

时间:2015-02-06 07:13:50

标签: android gridview android-recyclerview

每次在recyclerview中更新图像列表时都会出现轻微的图像闪烁,我在GridView中面临同样的问题,这是通过在这样的持有者中设置图像url的标记来解决的,

//for solving image flicker
if(contentViewHolder.ivPhoto.getTag()==null || (!contentViewHolder.ivPhoto.getTag().equals(currentMoment.getThumbnailUrl()))){
            mImageLoader.displayImage(currentMoment.getThumbnailUrl(), contentViewHolder.ivPhoto);
        }

        contentViewHolder.ivPhoto.setTag(currentMoment.getThumbnailUrl());

这在gridview中工作得很好,但是如果在recyclerview的情况下它没有解决图像闪烁,有人可以建议我如何在回收者视图的情况下停止图像闪烁吗?

2 个答案:

答案 0 :(得分:5)

如果要更改所有列表项,则仅使用notifyDataSetChanged。 在其他情况下,您应该使用: -

  • notifyItemChanged(int)
  • notifyItemInserted(int)的
  • notifyItemRemoved(int)的

有关更多信息,请参阅(官方文件)的以下链接: - https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#notifyDataSetChanged%28%29

答案 1 :(得分:1)

可能是由于另一个视图被回收造成的。

尝试使用类似setImageDrawable(null)的内容将视图重置为onBindViewHolder()的开头;