Glide版本4,Glide.clear(ImageView)不再存在

时间:2019-02-19 18:13:31

标签: android-glide

在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)
} 

不起作用,请参阅Glide的评论:

<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));
  }

2 个答案:

答案 0 :(得分:0)

找到了解决方案,添加了kotlin扩展程序即可解决问题:

fun ImageView.clear() {
   Glide.with(this.context).clear(this)
}

答案 1 :(得分:0)

对于Java

$ sudo ls -l -a /usr/share/wordpress/
total 180
drwxrw-r--   5 www-data www-data  4096 Jul 20 17:13 .
drwxr-xr-x 162 root     root      4096 Jul 20 02:40 ..
...