Вы можете попробовать с помощью Request Listner в Glide.
Используйте приведенный ниже код для Kotlin:
Glide.with(context).load(imageUrl)
.apply(RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL))
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?, target: com.bumptech.glide.request.target.Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
return false
}
override fun onResourceReady(
resource: Drawable?,model: Any?,
target: com.bumptech.glide.request.target.Target<Drawable>?,
dataSource: DataSource?, isFirstResource: Boolean
): Boolean {
view.setBackground(resource)
return true
}
})
.into(view)
Для Java:
Glide.with(this).load("imageUrl")
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
view.setBackground(resource);
return false;
}
}).into(view);