美文网首页
Glide 出现 You must not call setTa

Glide 出现 You must not call setTa

作者: wuchao226 | 来源:发表于2020-02-26 19:43 被阅读0次

原因

原因就是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加上

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="glide_tag" type="id" />
</resources>

相关文章

网友评论

      本文标题:Glide 出现 You must not call setTa

      本文链接:https://www.haomeiwen.com/subject/ceqichtx.html