Glide Recyclerview正在加载重复图像 [英] Glide recyclerview loading duplicate image

查看:938
本文介绍了Glide Recyclerview正在加载重复图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个recyclerviewdiffutil.我已经使用GlideImageViews内部加载图像.

I have a recyclerview with diffutil. Already I using Glide to load images inside the ImageViews.

onBindViewHolder上,我将其称为函数loadImage(holder.view,item)

on the onBindViewHolder I call my function it's called loadImage(holder.view,item)

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    val item = getItem(position)

    onLoadImage(holder.view, item)
}

在我的loadImage中,我将图像加载到视图中.

In my loadImage I load the image inside the view.

 private fun loadImage(view: View, item: MyItemModel) {
        Timber.i("load item's image id: ${item.id} image is: ${item.image}")

        Glide.with(context)
                .asDrawable()
                .load(item.image)
                .into(view.main_image)
    }

效果很好,但是第一次加载图像时,我在列表中滑动,图像显示如下:

It works good, but when first time when It's loading the image than I swipe in the list, and the Images are shows like this:

因此图像是重复的,但是最后两个图像是不同的.仅当加载时我快速滑动时才会发生. 日志:

So the Images are duplicated, but the last two image is different. It happens only if I swipe fast when It's loading. Log:

I/MyListAdapter: load image into : 6 image is: [B@25d0674
I/MyListAdapter: load image into : 7 image is: [B@e64ced4
I/MyListAdapter: load image into : 8 image is: [B@b384734

这是一个自定义视图.上下文就是视图的上下文.

This is a Custom View. Context is that's view's context.

因此图像不同. 问题是什么?

So the Images are different. What is the problem?

有什么建议吗?

推荐答案

在将新图像加载到loadImage方法之前,请尝试清除图像:

Try clearing the image before loading a new one in your loadImage method:

view.main_image.setImageBitmap(null)
Glide.with(...)

这篇关于Glide Recyclerview正在加载重复图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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