Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide not loading image from memory at the first time when rotating (orientation change), and after that it is loading from memory

Glide not loading image from memory at the first time when rotating (orientation change), and after that it is loading from memory.

I have tried to increase the memory size, the bitmap pool size, all kinds of caching strategies... nothing seemed to work...

I have attached a video.

https://youtu.be/szDnAGxrJLU

Thanks!

like image 696
oznus Avatar asked Aug 26 '15 21:08

oznus


3 Answers

.dontAnimate() adding this to Glide solved my problem

Glide.with(view.getContext())
            .load(url)
            .placeholder(placeholder_image_crop))
            .dontAnimate()
            .into(view)

You may face this issue because of

CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.

for more queries refer following links it may help you. link 1 and link 2

like image 75
Sagar Avatar answered Oct 05 '22 13:10

Sagar


Your ImageViews don't have the exact same size in portrait and in landscape and you are probably using fitCenter() or centerCrop() to resize the image to the ImageView size. When you change orientation, Glide loads the full-sized image from cache but it has to resize it on a background thread first before display, that's why you see a delay after the first orientation change. After resized images for both portrait and landscape are in the memory cache, there is no more delay.

like image 29
BladeCoder Avatar answered Oct 05 '22 13:10

BladeCoder


Just to emphasize what is written above and add a solution.

It is possible to change the disk caching strategy to cache the source image but not the memory caching strategy, in that case it will not hit unless it is the same size.

What i did was use .override(width,height) in order to override this strategy and keep the source image in the memory cache.

        Glide.with(context)
             .load(imgUrl)
             .crossFade()
             .override(imageWidth,imageHeight)
             .into(imgView);
like image 35
oznus Avatar answered Oct 05 '22 13:10

oznus