A fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.
—
The Glide request configuration system provides comprehensive control over how images are loaded, cached, transformed, and displayed. At its core is the RequestOptions class, which offers an immutable, fluent API for configuring all aspects of image requests.
The RequestOptions class is the primary configuration interface for Glide requests. It provides a builder pattern for setting up request parameters and can be applied globally or per-request.
public class RequestOptions {
/**
* Creates a new RequestOptions instance
*/
public static RequestOptions new() {
// Implementation creates new instance
}
/**
* Creates RequestOptions with placeholder
* @param placeholderDrawable The placeholder drawable
*/
public static RequestOptions placeholderOf(Drawable placeholderDrawable) {
// Implementation creates instance with placeholder
}
/**
* Creates RequestOptions with error drawable
* @param errorDrawable The error drawable
*/
public static RequestOptions errorOf(Drawable errorDrawable) {
// Implementation creates instance with error drawable
}
/**
* Creates RequestOptions with format
* @param format The decode format preference
*/
public static RequestOptions formatOf(DecodeFormat format) {
// Implementation creates instance with format
}
/**
* Creates RequestOptions with priority
* @param priority The request priority level
*/
public static RequestOptions priorityOf(Priority priority) {
// Implementation creates instance with priority
}
/**
* Creates RequestOptions with disk cache strategy
* @param strategy The caching strategy
*/
public static RequestOptions diskCacheStrategyOf(DiskCacheStrategy strategy) {
// Implementation creates instance with strategy
}
/**
* Creates RequestOptions with size override
* @param width Target width in pixels
* @param height Target height in pixels
*/
public static RequestOptions overrideOf(int width, int height) {
// Implementation creates instance with size override
}
}Control what displays during loading states and error conditions:
/**
* Sets the placeholder drawable to display while loading
* @param placeholderDrawable Drawable to show during loading
*/
public RequestOptions placeholder(Drawable placeholderDrawable);
/**
* Sets placeholder using resource ID
* @param placeholderResourceId Resource ID for placeholder
*/
public RequestOptions placeholder(@DrawableRes int placeholderResourceId);
/**
* Sets the error drawable for failed loads
* @param errorDrawable Drawable to show on error
*/
public RequestOptions error(Drawable errorDrawable);
/**
* Sets error drawable using resource ID
* @param errorResourceId Resource ID for error drawable
*/
public RequestOptions error(@DrawableRes int errorResourceId);
/**
* Sets fallback drawable for null models
* @param fallbackDrawable Drawable for null/empty sources
*/
public RequestOptions fallback(Drawable fallbackDrawable);
/**
* Sets fallback using resource ID
* @param fallbackResourceId Resource ID for fallback
*/
public RequestOptions fallback(@DrawableRes int fallbackResourceId);Control image dimensions and scaling behavior:
/**
* Overrides the target size for the request
* @param width Target width in pixels
* @param height Target height in pixels
*/
public RequestOptions override(int width, int height);
/**
* Sets a multiplier for the target size
* @param sizeMultiplier Multiplier (0.1f to 1.0f)
*/
public RequestOptions sizeMultiplier(float sizeMultiplier);Control request execution priority and timing:
/**
* Sets the priority for this request
* @param priority Priority level for execution
*/
public RequestOptions priority(Priority priority);
/**
* Sets timeout for the request
* @param timeoutMs Timeout in milliseconds
*/
public RequestOptions timeout(int timeoutMs);Control image format and compression:
/**
* Sets the decode format preference
* @param format Preferred bitmap configuration
*/
public RequestOptions format(DecodeFormat format);
/**
* Sets the class to decode into
* @param resourceClass Target class (Bitmap, Drawable, etc.)
*/
public <T> RequestOptions decode(Class<T> resourceClass);
/**
* Sets bitmap compress format for encoding
* @param format Compression format (JPEG, PNG, WEBP)
*/
public RequestOptions encodeFormat(Bitmap.CompressFormat format);
/**
* Sets encoding quality (0-100)
* @param quality Quality percentage
*/
public RequestOptions encodeQuality(int quality);Manage caching behavior:
/**
* Sets disk cache strategy
* @param strategy How to cache on disk
*/
public RequestOptions diskCacheStrategy(DiskCacheStrategy strategy);
/**
* Controls memory cache usage
* @param skip True to skip memory cache
*/
public RequestOptions skipMemoryCache(boolean skip);
/**
* Only load from cache, don't fetch
* @param onlyCache True to use cache only
*/
public RequestOptions onlyRetrieveFromCache(boolean onlyCache);Configure video frame loading:
/**
* Sets the time position for video frame extraction
* @param frameTimeMicros Time in microseconds
*/
public RequestOptions frame(long frameTimeMicros);Additional configuration options:
/**
* Controls unlimited source generators pool usage
* @param flag True to use unlimited pool
*/
public RequestOptions useUnlimitedSourceGeneratorsPool(boolean flag);public enum Priority {
/**
* Lowest priority - loaded when system is idle
*/
LOW,
/**
* Normal priority - default for most requests
*/
NORMAL,
/**
* High priority - important images
*/
HIGH,
/**
* Immediate priority - critical images
*/
IMMEDIATE
}public enum DecodeFormat {
/**
* Prefer ARGB_8888 for quality (default)
*/
PREFER_ARGB_8888,
/**
* Prefer RGB_565 for memory efficiency
*/
PREFER_RGB_565,
/**
* Use system default format
*/
DEFAULT
}public enum DiskCacheStrategy {
/**
* Cache both original and transformed resources
*/
ALL,
/**
* Cache nothing to disk
*/
NONE,
/**
* Cache only original untransformed data
*/
DATA,
/**
* Cache only transformed resources
*/
RESOURCE,
/**
* Intelligently cache based on data source (default)
*/
AUTOMATIC
}// Create base options
RequestOptions baseOptions = new RequestOptions()
.placeholder(R.drawable.loading)
.error(R.drawable.error)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH);
// Apply to specific request
Glide.with(context)
.load(imageUrl)
.apply(baseOptions)
.into(imageView);
// Chain additional options
Glide.with(context)
.load(imageUrl)
.apply(baseOptions)
.override(300, 300)
.format(DecodeFormat.PREFER_RGB_565)
.into(imageView);// Set global defaults in GlideModule
public class MyGlideModule extends AppGlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
RequestOptions defaultOptions = new RequestOptions()
.format(DecodeFormat.PREFER_RGB_565)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.timeout(30000);
builder.setDefaultRequestOptions(defaultOptions);
}
}// Memory-efficient configuration
RequestOptions memoryEfficientOptions = new RequestOptions()
.format(DecodeFormat.PREFER_RGB_565) // Use less memory
.sizeMultiplier(0.8f) // Scale down slightly
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) // Cache processed images
.skipMemoryCache(false); // Keep memory caching
Glide.with(context)
.load(imageUrl)
.apply(memoryEfficientOptions)
.into(imageView);// High-quality configuration
RequestOptions highQualityOptions = new RequestOptions()
.format(DecodeFormat.PREFER_ARGB_8888) // Best quality
.encodeFormat(Bitmap.CompressFormat.PNG) // Lossless compression
.encodeQuality(100) // Maximum quality
.diskCacheStrategy(DiskCacheStrategy.ALL) // Cache everything
.priority(Priority.HIGH); // High priority loading
Glide.with(context)
.load(imageUrl)
.apply(highQualityOptions)
.into(imageView);// Extract frame from video
RequestOptions videoThumbnailOptions = new RequestOptions()
.frame(1000000) // 1 second in microseconds
.placeholder(R.drawable.video_placeholder)
.error(R.drawable.video_error)
.override(200, 150) // Thumbnail size
.diskCacheStrategy(DiskCacheStrategy.RESOURCE);
Glide.with(context)
.load(videoUri)
.apply(videoThumbnailOptions)
.into(thumbnailView);// Optimized for list scrolling
RequestOptions listItemOptions = new RequestOptions()
.placeholder(new ColorDrawable(Color.LTGRAY)) // Lightweight placeholder
.format(DecodeFormat.PREFER_RGB_565) // Memory efficient
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) // Smart caching
.priority(Priority.NORMAL) // Standard priority
.timeout(10000); // Shorter timeout
// In adapter
Glide.with(holder.itemView.getContext())
.load(item.imageUrl)
.apply(listItemOptions)
.into(holder.imageView);// Prefer cached content
RequestOptions cacheFirstOptions = new RequestOptions()
.onlyRetrieveFromCache(true) // Only use cache
.fallback(R.drawable.offline_placeholder) // Show when no cache
.skipMemoryCache(false) // Use memory cache
.diskCacheStrategy(DiskCacheStrategy.ALL);
Glide.with(context)
.load(imageUrl)
.apply(cacheFirstOptions)
.into(imageView);// Progressive loading with thumbnail
RequestOptions progressiveOptions = new RequestOptions()
.placeholder(R.drawable.loading)
.sizeMultiplier(0.1f); // Small thumbnail first
RequestOptions fullSizeOptions = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH);
Glide.with(context)
.load(imageUrl)
.thumbnail(
Glide.with(context)
.load(imageUrl)
.apply(progressiveOptions)
)
.apply(fullSizeOptions)
.into(imageView);The RequestOptions system provides fine-grained control over every aspect of image loading in Glide. By understanding these configuration options and applying them appropriately, you can optimize your app's performance, memory usage, and user experience while maintaining high image quality where needed.
Install with Tessl CLI
npx tessl i tessl/maven-com-github-bumptech-glide--glide