为什么在notifydatasetchanged时Glide会闪烁项目ImageView

编程入门 行业动态 更新时间:2024-10-25 08:15:03
本文介绍了为什么在notifydatasetchanged时Glide会闪烁项目ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用 Glide 3.7.0 和 RecyclerView.刷新时项目视图总是闪烁(调用 notifyDataSetChanged).

I am using Glide 3.7.0 with RecyclerView. The item view always blinks when refreshing (calling notifyDataSetChanged).

这是我的代码:

Glide .with(context) .load(filepath) .diskCacheStrategy(DiskCacheStrategy.NONE) .skipMemoryCache(true) .dontAnimate() .into(imageview);

当我不使用缓存时,当 notifyDataSetChanged 方法被调用并且 Glide 没有完成加载位图时,ImageView 有一个空位图.

When I use no cache, the ImageView has a null Bitmap when notifyDataSetChanged method is called and Glide hasn't finished loading the bitmap.

如果我使用下面的代码:

If I use the code below:

Glide .with(context) .load(filepath) .dontAnimate() .into(imageview);

然后项目 ImageView 不再闪烁(使用缓存).

Then the item ImageView does not blink anymore (using cache).

我想动态更新 item 视图,所以我禁用了 glide 缓存.

I want to update the item view dynamically, so I disable the glide cache.

是否有解决此闪烁错误的解决方案?

Are there any solutions to solve this blink bug?

非常感谢!

推荐答案

经过多次尝试,使用 SimpleTarget 解决了我的问题谢谢!

After my many tries, just use SimpleTarget solved my problem thank you!

Glide .with(context) .load(filepath) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.NONE) .skipMemoryCache(true) .dontAnimate() .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap arg0, GlideAnimation<? super Bitmap> arg1) { // TODO Auto-generated method stub holder.mItemView.setImageBitmap(arg0); } });

更多推荐

为什么在notifydatasetchanged时Glide会闪烁项目ImageView

本文发布于:2023-11-26 17:44:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   notifydatasetchanged   Glide   ImageView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!