类 ImageLoader
java.lang.Object
com.android.volley.toolbox.ImageLoader
Helper that handles loading and caching images from remote URLs.
The simple way to use this class is to call
get(String, ImageListener)
and to pass in the default image listener provided by
getImageListener(ImageView, int, int). Note that all function calls to
this class must be made from the main thead, and all responses will be delivered to the main
thread as well.-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceSimple cache adapter interface.classContainer object for all of the data surrounding an image request.static interfaceInterface for the response handlers on image requests. -
构造器概要
构造器构造器说明ImageLoader(RequestQueue queue, ImageLoader.ImageCache imageCache) Constructs a new ImageLoader. -
方法概要
修饰符和类型方法说明get(String requestUrl, ImageLoader.ImageListener listener) Returns an ImageContainer for the requested URL.get(String requestUrl, ImageLoader.ImageListener imageListener, int maxWidth, int maxHeight) Equivalent to callingget(String, ImageListener, int, int, ScaleType)withScaletype == ScaleType.CENTER_INSIDE.get(String requestUrl, ImageLoader.ImageListener imageListener, int maxWidth, int maxHeight, android.widget.ImageView.ScaleType scaleType) Issues a bitmap request with the given URL if that image is not available in the cache, and returns a bitmap container that contains all of the data relating to the request (as well as the default image if the requested image is not available).static ImageLoader.ImageListenergetImageListener(android.widget.ImageView view, int defaultImageResId, int errorImageResId) The default implementation of ImageListener which handles basic functionality of showing a default image until the network response is received, at which point it will switch to either the actual image or the error image.booleanChecks if the item is available in the cache.booleanisCached(String requestUrl, int maxWidth, int maxHeight, android.widget.ImageView.ScaleType scaleType) Checks if the item is available in the cache.protected Request<android.graphics.Bitmap>makeImageRequest(String requestUrl, int maxWidth, int maxHeight, android.widget.ImageView.ScaleType scaleType, String cacheKey) protected voidonGetImageError(String cacheKey, VolleyError error) Handler for when an image failed to load.protected voidonGetImageSuccess(String cacheKey, android.graphics.Bitmap response) Handler for when an image was successfully loaded.voidsetBatchedResponseDelay(int newBatchedResponseDelayMs) Sets the amount of time to wait after the first response arrives before delivering all responses.
-
构造器详细资料
-
ImageLoader
Constructs a new ImageLoader.- 参数:
queue- The RequestQueue to use for making image requests.imageCache- The cache to use as an L1 cache.
-
-
方法详细资料
-
getImageListener
public static ImageLoader.ImageListener getImageListener(android.widget.ImageView view, int defaultImageResId, int errorImageResId) The default implementation of ImageListener which handles basic functionality of showing a default image until the network response is received, at which point it will switch to either the actual image or the error image.- 参数:
view- The imageView that the listener is associated with.defaultImageResId- Default image resource ID to use, or 0 if it doesn't exist.errorImageResId- Error image resource ID to use, or 0 if it doesn't exist.
-
isCached
Checks if the item is available in the cache.- 参数:
requestUrl- The url of the remote imagemaxWidth- The maximum width of the returned image.maxHeight- The maximum height of the returned image.- 返回:
- True if the item exists in cache, false otherwise.
-
isCached
public boolean isCached(String requestUrl, int maxWidth, int maxHeight, android.widget.ImageView.ScaleType scaleType) Checks if the item is available in the cache.- 参数:
requestUrl- The url of the remote imagemaxWidth- The maximum width of the returned image.maxHeight- The maximum height of the returned image.scaleType- The scaleType of the imageView.- 返回:
- True if the item exists in cache, false otherwise.
-
get
Returns an ImageContainer for the requested URL. The ImageContainer will contain either the specified default bitmap or the loaded bitmap. If the default was returned, theImageLoaderwill be invoked when the request is fulfilled.- 参数:
requestUrl- The URL of the image to be loaded.
-
get
public ImageLoader.ImageContainer get(String requestUrl, ImageLoader.ImageListener imageListener, int maxWidth, int maxHeight) Equivalent to callingget(String, ImageListener, int, int, ScaleType)withScaletype == ScaleType.CENTER_INSIDE. -
get
public ImageLoader.ImageContainer get(String requestUrl, ImageLoader.ImageListener imageListener, int maxWidth, int maxHeight, android.widget.ImageView.ScaleType scaleType) Issues a bitmap request with the given URL if that image is not available in the cache, and returns a bitmap container that contains all of the data relating to the request (as well as the default image if the requested image is not available).- 参数:
requestUrl- The url of the remote imageimageListener- The listener to call when the remote image is loadedmaxWidth- The maximum width of the returned image.maxHeight- The maximum height of the returned image.scaleType- The ImageViews ScaleType used to calculate the needed image size.- 返回:
- A container object that contains all of the properties of the request, as well as the currently available image (default if remote is not loaded).
-
makeImageRequest
-
setBatchedResponseDelay
public void setBatchedResponseDelay(int newBatchedResponseDelayMs) Sets the amount of time to wait after the first response arrives before delivering all responses. Batching can be disabled entirely by passing in 0.- 参数:
newBatchedResponseDelayMs- The time in milliseconds to wait.
-
onGetImageSuccess
Handler for when an image was successfully loaded.- 参数:
cacheKey- The cache key that is associated with the image request.response- The bitmap that was returned from the network.
-
onGetImageError
Handler for when an image failed to load.- 参数:
cacheKey- The cache key that is associated with the image request.
-