ViewTarget

abstract class ViewTarget<T : View?, Z> : BaseTarget<Z>

A base Target for loading android.graphics.Bitmaps into Views that provides default implementations for most most methods and can determine the size of views using a android.view.ViewTreeObserver.OnDrawListener.

To detect View reuse in android.widget.ListView or any that reuses views, this class uses the setTag method 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 setTag} on a View given to this class will result in excessive allocations and and/or IllegalArgumentExceptions. If you must call setTag on a view, use setTagId to specify a custom tag for Glide to use.

Subclasses must call super in onLoadCleared

Deprecated

Use CustomViewTarget. Using this class is unsafe without implementing onLoadCleared and results in recycled bitmaps being referenced from the UI and hard to root-cause crashes.

Parameters

<T>

The specific subclass of view wrapped by this target.

<Z>

The resource type this target will receive.

Constructors

Link copied to clipboard
open fun ViewTarget(view: T)
Constructor that defaults waitForLayout to false.
Link copied to clipboard
open fun ViewTarget(view: T, waitForLayout: Boolean)

Functions

Link copied to clipboard
fun clearOnDetach(): ViewTarget<T, Z>
Clears the View's Request when the View is detached from its and restarts the Request when the View is re-attached from its android.view.
Link copied to clipboard
open fun getRequest(): Request
Returns any stored request using getTag.
Link copied to clipboard
open fun getSize(cb: SizeReadyCallback)
Determines the size of the view by first checking getWidth and getHeight.
Link copied to clipboard
open fun getView(): T
Returns the wrapped android.view.
Link copied to clipboard
open fun onDestroy()
Callback for when onDestroy} or onDestroy is called.
Link copied to clipboard
open fun onLoadCleared(placeholder: Drawable)
A mandatory lifecycle callback that is called when a load is cancelled and its resources are freed.
Link copied to clipboard
open fun onLoadFailed(errorDrawable: Drawable)
A mandatory lifecycle callback that is called when a load fails.
Link copied to clipboard
open fun onLoadStarted(placeholder: Drawable)
A lifecycle callback that is called when a load is started.
Link copied to clipboard
abstract fun onResourceReady(resource: R, transition: Transition<out Any>)
The method that will be called when the resource load has finished.
Link copied to clipboard
open fun onStart()
Callback for when onStart} or onStart is called.
Link copied to clipboard
open fun onStop()
Callback for when onStop} or onStop} is called.
Link copied to clipboard
open fun removeCallback(cb: SizeReadyCallback)
Removes the given callback from the pending set if it's still retained.
Link copied to clipboard
open fun setRequest(request: Request)
Stores the request using setTag.
Link copied to clipboard
open fun setTagId(tagId: Int)
Sets the android resource id to use in conjunction with setTag to store temporary state allowing loads to be automatically cancelled and resources re-used in scrolling lists.
Link copied to clipboard
open fun toString(): String
Link copied to clipboard
fun waitForLayout(): ViewTarget<T, Z>
Indicates that Glide should always wait for any pending layout pass before checking for the size an View.

Properties

Link copied to clipboard
val SIZE_ORIGINAL: Int
Indicates that we want the resource in its original unmodified width and/or height.

Inheritors

Link copied to clipboard