Glide 出现 You must not call setTag() on a view Glide is targeting 的解决方案

原因

原因就是View使用setTag后导致Glide之前请求的标记被清除,强制转换过程中不能将你给定的类型判断为Request类型所致。
Glide为了防止加载图片错乱已经给图片打上标记了。

@Override
  @Nullable
  public Request getRequest() {
    Object tag = getTag();
    Request request = null;
    if (tag != null) {
      if (tag instanceof Request) {
        request = (Request) tag;
      } else {
        throw new IllegalArgumentException(
            "You must not call setTag() on a view Glide is targeting");
      }
    }
    return request;
  }

解决方法

自定义一个Application,在里面加上

public class App extends Application {
    @Override public void onCreate() {
        super.onCreate();
        ViewTarget.setTagId(R.id.glide_tag);
    }
}

然后在/values/ids.xml加上



    

你可能感兴趣的:(Glide 出现 You must not call setTag() on a view Glide is targeting 的解决方案)