0
# Glide
1
2
Glide is a comprehensive Android image loading library that provides fast and efficient media management capabilities for mobile applications. It features automatic memory and disk caching, supports multiple image formats including animated GIFs and video stills, offers seamless integration with various network stacks, and provides a fluent API for common transformations. The library is specifically optimized for smooth scrolling performance in lists and grids with built-in lifecycle management.
3
4
## Package Information
5
6
- **Package Name**: com.github.bumptech.glide:glide
7
- **Package Type**: Maven/Gradle
8
- **Language**: Java
9
- **Installation**: `implementation 'com.github.bumptech.glide:glide:4.16.0'`
10
- **Minimum Android SDK**: API 14 (Android 4.0)
11
12
## Core Imports
13
14
```java
15
import com.bumptech.glide.Glide;
16
import com.bumptech.glide.RequestManager;
17
import com.bumptech.glide.RequestBuilder;
18
import com.bumptech.glide.request.RequestOptions;
19
```
20
21
## Basic Usage
22
23
```java
24
// Basic image loading into ImageView
25
Glide.with(context)
26
.load("https://example.com/image.jpg")
27
.into(imageView);
28
29
// With placeholder and error handling
30
Glide.with(context)
31
.load(imageUrl)
32
.placeholder(R.drawable.loading)
33
.error(R.drawable.error)
34
.into(imageView);
35
36
// With transformations
37
Glide.with(context)
38
.load(imageUrl)
39
.centerCrop()
40
.transform(new RoundedCorners(16))
41
.into(imageView);
42
```
43
44
## Architecture
45
46
Glide is built around several key components:
47
48
- **Entry Point**: `Glide` class provides lifecycle-aware request management
49
- **Request System**: Fluent API through `RequestManager` and `RequestBuilder` classes
50
- **Target System**: Flexible destination handling for images (ImageView, custom targets, etc.)
51
- **Transformation Pipeline**: Built-in and custom image transformations (crop, resize, effects)
52
- **Caching Strategy**: Multi-level caching (memory, disk) with configurable policies
53
- **Extension System**: Modular architecture with custom modules, loaders, and decoders
54
55
## Capabilities
56
57
### Core Request Management
58
59
Essential image loading functionality with lifecycle awareness and fluent API for common use cases.
60
61
```java { .api }
62
// Main entry point - lifecycle aware
63
public static RequestManager with(Context context);
64
public static RequestManager with(Activity activity);
65
public static RequestManager with(Fragment fragment);
66
public static RequestManager with(FragmentActivity activity);
67
68
// Request building
69
public RequestBuilder<Drawable> load(String string);
70
public RequestBuilder<Drawable> load(Uri uri);
71
public RequestBuilder<Drawable> load(File file);
72
public RequestBuilder<Drawable> load(Integer resourceId);
73
public RequestBuilder<Drawable> load(byte[] model);
74
```
75
76
[Request Management](./request-management.md)
77
78
### Image Targets and Loading
79
80
Flexible target system for loading images into various UI components and custom destinations.
81
82
```java { .api }
83
// Primary loading methods
84
public ViewTarget<ImageView, TranscodeType> into(ImageView view);
85
public <Y extends Target<TranscodeType>> Y into(Y target);
86
public FutureTarget<TranscodeType> submit();
87
public FutureTarget<TranscodeType> submit(int width, int height);
88
89
// Request execution
90
public Target<TranscodeType> preload();
91
public Target<TranscodeType> preload(int width, int height);
92
```
93
94
[Targets and Loading](./targets-loading.md)
95
96
### Request Configuration
97
98
Comprehensive configuration options for customizing image loading behavior, including placeholders, caching, and sizing.
99
100
```java { .api }
101
// Request options
102
public RequestBuilder<TranscodeType> placeholder(@DrawableRes int resourceId);
103
public RequestBuilder<TranscodeType> placeholder(@Nullable Drawable drawable);
104
public RequestBuilder<TranscodeType> error(@DrawableRes int resourceId);
105
public RequestBuilder<TranscodeType> error(@Nullable Drawable drawable);
106
public RequestBuilder<TranscodeType> fallback(@DrawableRes int resourceId);
107
108
// Sizing and priority
109
public RequestBuilder<TranscodeType> override(int width, int height);
110
public RequestBuilder<TranscodeType> priority(@NonNull Priority priority);
111
public RequestBuilder<TranscodeType> timeout(@IntRange(from = 0) int timeoutMs);
112
```
113
114
[Request Configuration](./request-configuration.md)
115
116
### Image Transformations
117
118
Built-in and custom transformations for manipulating images including cropping, scaling, effects, and custom modifications.
119
120
```java { .api }
121
// Built-in transformations
122
public RequestBuilder<TranscodeType> centerCrop();
123
public RequestBuilder<TranscodeType> centerInside();
124
public RequestBuilder<TranscodeType> fitCenter();
125
public RequestBuilder<TranscodeType> circleCrop();
126
127
// Custom transformations
128
public RequestBuilder<TranscodeType> transform(@NonNull Transformation<Bitmap> transformation);
129
public RequestBuilder<TranscodeType> transform(@NonNull Transformation<Bitmap>... transformations);
130
```
131
132
[Transformations](./transformations.md)
133
134
### Caching Strategies
135
136
Advanced caching system with memory and disk cache control for optimal performance and resource management.
137
138
```java { .api }
139
// Cache control
140
public RequestBuilder<TranscodeType> diskCacheStrategy(@NonNull DiskCacheStrategy strategy);
141
public RequestBuilder<TranscodeType> skipMemoryCache(boolean skip);
142
public RequestBuilder<TranscodeType> onlyRetrieveFromCache(boolean onlyRetrieveFromCache);
143
144
// Cache strategies
145
public enum DiskCacheStrategy {
146
ALL, NONE, DATA, RESOURCE, AUTOMATIC
147
}
148
```
149
150
[Caching Strategies](./caching-strategies.md)
151
152
### Transitions and Animations
153
154
Animation and transition effects for smooth image loading including cross-fades and custom transitions.
155
156
```java { .api }
157
// Transition options
158
public RequestBuilder<TranscodeType> transition(@NonNull TransitionOptions<?, ? super TranscodeType> transitionOptions);
159
160
// Built-in transitions
161
public static DrawableTransitionOptions withCrossFade();
162
public static DrawableTransitionOptions withCrossFade(int duration);
163
public static DrawableTransitionOptions with(@NonNull TransitionFactory<? super Drawable> transitionFactory);
164
```
165
166
[Transitions and Animations](./transitions-animations.md)
167
168
### Modules and Configuration
169
170
Global configuration and extension system for customizing Glide behavior, including custom loaders, decoders, and cache implementations.
171
172
```java { .api }
173
// Module interfaces
174
public interface GlideModule {
175
void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder);
176
void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry);
177
}
178
179
// Configuration builder
180
public final class GlideBuilder {
181
public GlideBuilder setBitmapPool(@Nullable BitmapPool bitmapPool);
182
public GlideBuilder setMemoryCache(@Nullable MemoryCache memoryCache);
183
public GlideBuilder setDiskCache(@Nullable DiskCache.Factory diskCacheFactory);
184
}
185
```
186
187
[Modules and Configuration](./modules-configuration.md)
188
189
### Error Handling and Debugging
190
191
Error handling patterns, debugging utilities, and troubleshooting for image loading issues.
192
193
```java { .api }
194
// Request listeners
195
public interface RequestListener<R> {
196
boolean onLoadFailed(@Nullable GlideException e, Object model, Target<R> target, boolean isFirstResource);
197
boolean onResourceReady(R resource, Object model, Target<R> target, DataSource dataSource, boolean isFirstResource);
198
}
199
200
// Exception handling
201
public RequestBuilder<TranscodeType> listener(@Nullable RequestListener<TranscodeType> requestListener);
202
```
203
204
[Error Handling and Debugging](./error-handling-debugging.md)
205
206
## Types
207
208
```java { .api }
209
// Core enums
210
public enum Priority {
211
LOW, NORMAL, HIGH, IMMEDIATE
212
}
213
214
public enum DecodeFormat {
215
PREFER_ARGB_8888, PREFER_RGB_565, DEFAULT
216
}
217
218
// Data source information
219
public enum DataSource {
220
LOCAL, REMOTE, DATA_DISK_CACHE, RESOURCE_DISK_CACHE, MEMORY_CACHE
221
}
222
223
// Exception wrapper
224
public final class GlideException extends Exception {
225
@Nullable public Throwable getCause();
226
public List<Throwable> getRootCauses();
227
public void logRootCauses(@NonNull String tag);
228
}
229
```