Glide clear()方法无法解决

时间:2018-04-29 16:40:43

标签: android android-glide

我正在尝试在我的Android应用中修复OutOfMemoryException,在我想写的recyclerView中:

@Override
public void onViewRecycled(final ViewHolder viewHolder) {
    Glide.clear(viewHolder.getImageView());
}

但我收到错误:

  

错误:找不到符号方法清除(ImageView)

我正在使用:

implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'

1 个答案:

答案 0 :(得分:0)

根据clear方法的documentation

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

因此,您的OutOfMemoryException将通过明确的方法处理。

并稍微更改代码,将上下文传递给Glide:

Glide.with(viewHolder.getImageView().getContext()).clear(viewHolder.getImageView());