I'm using the Glide image loading library, and want to preload some images that I have stored on my device as a resource drawable (not an URL!).
So, when pressing buttons, a few images should be replaced (and in the end looping) in an ImageView
.
The problem is that the first time I enter the Fragment
and loop the images by pressing the buttons, the images blink (since they are loaded to the memory and then displayed). But when I've loaded all the images to the memory, the looping looks good (no blinking) and the images are shown instantly.
I just can't figure out how the preload works, and get rid of the blinking.
So I load my images like this (Simplified except for the GlideApp
lines):
// Do this when loading the fragment.
for (i in 0..9) {
for (j in 0..2) {
val resInt = getImages(i)[j] // Returns R.drawable.image1, R.drawable.image2 etc.
GlideApp.with(activity).load(resInt).diskCacheStrategy(DiskCacheStrategy.ALL).preload()
}
}
...
// Do this when pressing the buttons
loadImage(activity, getImages(0)[1], day_image_view) // Load R.drawable.image2
...
fun loadImage(context: Context, res: Int, imageView: ImageView) {
GlideApp.with(context).load(res).diskCacheStrategy(DiskCacheStrategy.ALL).dontAnimate().into(imageView)
}
Thank you and have a wonderful day <3