在recyclerView的适配器中,当调用OnBindViewHolder()并且来自回收器池的viewHolder被传入此位置时,imageView将更新为此位置的图像或根本没有图像用于此位置。
对于此位置没有图像的情况,使用Glide版本3,调用此clear()
以清除imageView:
Glide.clear(this.theImageView)
但是当升级到Glide 9时,它再也没有这个clear(ImageView)
了。
使用Glide 9清除ImageView图像的正确方法是什么?
更新:解决方案
fun ImageView.clear() {
Glide.with(this.context).clear(this)
}
不起作用,请看格莱德的评论:
<p> Note that this will only work if {@link View#setTag(Object)} is not called on this view outside of Glide. </p>
/**
* Cancel any pending loads Glide may have for the view and free any resources that may have been
* loaded for the view.
*
* <p> Note that this will only work if {@link View#setTag(Object)} is not called on this view
* outside of Glide. </p>
*
* @param view The view to cancel loads and free resources for.
* @throws IllegalArgumentException if an object other than Glide's metadata is put as the view's
* tag.
* @see #clear(Target)
*/
public void clear(@NonNull View view) {
clear(new ClearTarget(view));
}
找到了解决方案,添加kotlin扩展解决了这个问题:
fun ImageView.clear() {
Glide.with(this.context).clear(this)
}