T- The specific subclass of view wrapped by this target.
Z- The resource type this target will receive.
public abstract class ViewTarget<T extends View,Z> extends BaseTarget<Z>
Views that provides default implementations for most most methods and can determine the size of views using a
View reuse in
ListView or any
ViewGroup that reuses views, this class uses the
to store some metadata so that if a view is reused, any previous loads or resources from previous
loads can be cancelled or reused.
Any calls to
View.setTag(Object)} on a View given to this class will result in
excessive allocations and and/or
IllegalArgumentExceptions. If you must call
View.setTag(Object) on a view, consider using
Subclasses must call super in
|Modifier and Type||Field and Description|
|Constructor and Description|
Constructor that defaults
|Modifier and Type||Method and Description|
Returns any stored request using
Returns the wrapped
A lifecycle callback that is called when a load is cancelled and its resources are freed.
Removes the given callback from the pending set if it's still retained.
Stores the request using
Sets the android resource id to use in conjunction with
onDestroy, onLoadFailed, onLoadStarted, onStart, onStop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public ViewTarget(T view)
public ViewTarget(T view, boolean waitForLayout)
waitForLayout- If set to
true, Glide will always wait for any pending layout pass before checking for the size a View. If set to
falseGlide will only wait for a pending layout pass if it's unable to resolve the size from layout parameters or an existing View size. Because setting this parameter to
trueforces Glide to wait for the layout pass to occur before starting the load, setting this parameter to
truecan cause flashing in some cases and should be used sparingly. If layout parameters are set to fixed sizes, they will still be used instead of the View's dimensions even if this parameter is set to
true. This parameter is a fallback only.
public void getSize(SizeReadyCallback cb)
View.getHeight(). If one or both are zero, it then checks the view's
ViewGroup.LayoutParams. If one or both of the params width and height are less than or equal to zero, it then adds an
ViewTreeObserver.OnPreDrawListenerwhich waits until the view has been measured before calling the callback with the view's drawn width and height.
cb- The callback that must be called when the size of the target has been determined
public void removeCallback(SizeReadyCallback cb)
cb- The callback to remove.
public void onLoadCleared(Drawable placeholder)
You must ensure that any current Drawable received in
Transition) is no longer displayed before redrawing the container (usually a View) or
changing its visibility.
For Glide to function correctly, Glide must be the only thing that calls
View.setTag(Object). If the tag is cleared or put to another object type, Glide will not be
able to retrieve and cancel previous loads which will not only prevent Glide from reusing
resource, but will also result in incorrect images being loaded and lots of flashing of images
in lists. As a result, this will throw an
View.getTag()} returns a non null object that is not an
public static void setTagId(int tagId)
View.setTag(int, Object)to store temporary state allowing loads to be automatically cancelled and resources re-used in scrolling lists.
If no tag id is set, Glide will use
Warning: prior to Android 4.0 tags were stored in a static map. Using this method prior
to Android 4.0 may cause memory leaks and isn't recommended. If you do use this method
on older versions, be sure to call
any view you start a load into to ensure that the static state is removed.
tagId- The android resource to use.