Glide images
Skill almasumdev/awesome-java-android-agent-skills/.github/skills/ui/glide-images
Expert guidance on using Glide 4 from Java for image loading, caching, placeholders, thumbnails, and transformations. Use this when loading remote or local images on Android.From its SKILL.md
npx -y skills add almasumdev/awesome-java-android-agent-skills --skill glide-imagesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.6 KB, ~1.0k tokens by cl100k_base, as published. Nobody here has run it
Glide 4 Image Loading (Java)
Instructions
Glide is the default image loader. It handles lifecycle, memory cache, disk cache, and decoding off the main thread. Prefer Glide over Picasso for new code; prefer it over Coil when the project must stay Java.
1. Setup
dependencies {
implementation 'com.github.bumptech.glide:glide:4.16.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0'
}
With the annotation processor you get a generated GlideApp class. Register a module for app-wide defaults:
@GlideModule
public class AppGlideModule extends com.bumptech.glide.module.AppGlideModule {
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
builder.setDefaultRequestOptions(new RequestOptions()
.format(DecodeFormat.PREFER_RGB_565)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC));
builder.setMemoryCache(new LruResourceCache(1024L * 1024L * 40L)); // 40MB
}
@Override
public boolean isManifestParsingEnabled() { return false; }
}
2. Basic Load
Always pass a lifecycle-aware scope: pass this for Activity, this (Fragment), or the View.
Glide.with(imageView)
.load(article.imageUrl())
.placeholder(R.drawable.placeholder_article)
.error(R.drawable.error_article)
.into(imageView);
Never call Glide.with(getApplicationContext()) — it disables lifecycle cancellation and leaks.
3. Transformations
Glide.with(imageView)
.load(user.avatarUrl())
.transform(new CenterCrop(), new RoundedCorners(16))
.into(imageView);
Common transformations:
CenterCrop,CenterInside,FitCenterRoundedCorners(px)CircleCrop()for avatars- Custom
BitmapTransformationfor effects (blur, grayscale) — overridetransform()and return a newBitmap.
4. Thumbnails (fast perceived load)
RequestBuilder<Drawable> fullSize = Glide.with(imageView).load(article.imageUrl());
RequestBuilder<Drawable> thumb = Glide.with(imageView).load(article.thumbUrl());
fullSize.thumbnail(thumb).into(imageView);
Or a fractional thumbnail of the same URL:
Glide.with(imageView)
.load(url)
.thumbnail(0.25f)
.into(imageView);
5. RecyclerView
Cancel outstanding loads on view recycle:
@Override
public void onBindViewHolder(VH h, int pos) {
Article a = getItem(pos);
Glide.with(h.b.image)
.load(a.imageUrl())
.centerCrop()
.placeholder(R.color.image_placeholder)
.into(h.b.image);
}
@Override
public void onViewRecycled(@NonNull VH h) {
super.onViewRecycled(h);
Glide.with(h.b.image).clear(h.b.image);
}
Set fixed sizes (android:layout_width, android:layout_height) so Glide downsamples to the correct resolution. Avoid wrap_content on image views.
6. Preloading
For paging / detail screens, preload upcoming images:
RecyclerViewPreloader<Article> preloader = new RecyclerViewPreloader<>(
Glide.with(this),
new ListPreloader.PreloadModelProvider<>() {
@Override public List<Article> getPreloadItems(int position) {
return List.of(adapter.getItem(position));
}
@Override public RequestBuilder<?> getPreloadRequestBuilder(Article a) {
return Glide.with(recyclerView).load(a.imageUrl());
}
},
new ViewPreloadSizeProvider<>(),
10);
recyclerView.addOnScrollListener(preloader);
7. Disk / Memory Cache
DiskCacheStrategy.AUTOMATIC(default) is correct for most apps.- Use
DiskCacheStrategy.NONEfor one-off blobs (e.g. captchas). - Use
DiskCacheStrategy.ALLfor assets served with stable URLs. .skipMemoryCache(true)for debug overlays.
Clear caches on sign-out:
new Thread(() -> Glide.get(context).clearDiskCache()).start();
Glide.get(context).clearMemory();
Checklist
-
Glide.with(...)is called with a lifecycle-bound owner, notapplicationContext. - Every
ImageViewhas a fixed size or explicit constraint so Glide can downsample. - Placeholders and error drawables are set for network loads.
-
Glide.with(view).clear(view)is called inonViewRecycledfor long lists. - Avatars use
CircleCrop(), not a rounded background + mask hack. -
AppGlideModulesets reasonable cache sizes and defaultDecodeFormat.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.