Glide Exception:"You must not call setTag() on a view Glide is targeting"

来源:互联网 发布:王思仪铁观音淘宝店 编辑:程序博客网 时间:2024/06/07 15:36

How to solve the Glide Exception:”You must not call setTag() on a view Glide is targeting”

The following error encountered when you use the Glide image loading framework in the project.

这里写图片描述

异常原因:
Glide加载的iamgeView调用了setTag()方法,因为Glide已经默认为ImageView设置了Tag。

解决方案:
首先,在\res\values\文件夹下创建ids.xml文件(如果没有该文件的话),并添加以下代码:

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

其次,在项目中创建Application类(如果还没有Application类,名字自己起,根据你的项目),然后在Application的onCreate方法中添加:ViewTarget.setTagId(R.id.tag_glide);
例如:

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

最后,记得将在你的配置文件AndroidManifest.xml中做改动:application标签下添加android:name=”.SlideShowApp”,SlideShowApp替换为你的Application的类名。
例如:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.yuangudashen.testapp.slideshow">    <application        android:name=".SlideShowApp"        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme.NoActionBar.FullScreen">        <activity android:name="com.yuangudashen.testapp.slideshow.MainActivity">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>
阅读全文
1 0