如何在RecyclerView中删除相同的URL Glide缓存

时间:2019-04-16 10:49:05

标签: android kotlin android-recyclerview android-glide

我想加载一个将Rediffernet图片返回到RecyclerView项目中的URL。 问题是所有项目都具有相同的图像。 我正在使用下一个RequestOptions:

val options by lazy {
RequestOptions()
    .signature(ObjectKey(System.currentTimeMillis()))
    .diskCacheStrategy(DiskCacheStrategy.NONE)
    .skipMemoryCache(true)}

图片加载:

fun ImageView.load() {
Glide
    .with(this)
    .asBitmap()
    .load("url")
    .apply(options)
    .into(object : SimpleTarget<Bitmap>(1024, 1024) {
        override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
            useBitmap(resource)
            this@load.setImageBitmap(resource)
        }
    })}

绑定ViewHolder:

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    holder.bind(items[position])
}

class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
    fun bind(item: Model) = with(itemView) {
        itemView.image.load()
            ...
    }
}

1 个答案:

答案 0 :(得分:0)

尝试在设置图像之前在视图上调用滑行清除,我看到您没有将其缓存并跳过缓存,但是我也遇到过类似的情况,其中滑行尝试回收图像。