The key is ViewTarget.setTagId
; setting it will free up the default setTag
on the ImageView
so you can use it as root in the item layout.
It was introduced in Glide 3.6.0 in issue #370.
In your manifest add this:
<application
android:name=".App"
Then create an application context class:
public class App extends Application {
@Override public void onCreate() {
super.onCreate();
ViewTarget.setTagId(R.id.glide_tag);
}
}
Add the following as contents for src/main/values/ids.xml
:
<resources>
<item type="id" name="glide_tag" />
</resources>
(or just add the above <item ... />
into any resources
xml in values
)
Update: ViewTarget
was deprecated since 4.8.0. If you're using into(ImageView)
, you'll still have to call the deprecated class's method, because the built-in *ViewTarget
classes still extend the old class.
If you use a custom ViewTarget
, migrate to CustomViewTarget
as the replacement. This will remove the need for setting any tag ID, because the default behaviour for CustomViewTarget
is using a Glide-specific ID, so it shouldn't clash with any setTag
calls.
If you want to customise the ID anyway, you can use useTagId
on your custom target.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…