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

6

7

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!

Lubberly answered 26/8, 2015 at 21:56 Comment(1)
Here's the related Glide issue: github.com/bumptech/glide/issues/598Fitzger
H
5

.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

Hammack answered 25/2, 2019 at 4:46 Comment(2)
If you use de.hdodenhof.circleimageview.CircleImageView you'll need to add dontAnimate() as shown on this answerBerkman
This solved my issue as well. Image wouldn't load the first time the function is called once the fragment is created. I would destroy and recreate the fragment and then it would load. Adding dont animate() fixed it for meJurisprudence
I
3

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.

Irv answered 26/8, 2015 at 22:15 Comment(0)
L
2

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);
Lubberly answered 26/8, 2015 at 23:53 Comment(0)
M
0

To load image from cache you can pass DiskCacheStrategy.SOURCE to load images from cache.

You can use glide like below and keep don't animate method as it helps to load images in adapter without updating full list. For more check this

Glide.with(context)
    .load(row_object.getImage())
    .dontAnimate() // will load image
    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
    .placeholder(ContextCompat.getDrawable(context,
        R.mipmap.ic_user_placeholder_50dp))
    .into(holder.rowIvPostUserIcon);
Macnair answered 14/7, 2017 at 11:8 Comment(4)
.dontAnimate() adding this to Glide solved my problem. thanksHammack
Same for me @Sagar. The image didn't load the first time (had to open another screen and go back to see it). Adding .dontAnimate() fixed the issue. I've used Glide since 2015 but never had to do this before. Really weird :/Berkman
@AlbertVilaCalvo the problem is with circular image view please check the the answer I have posted below.Hammack
Thanks @Hammack the project I'm working on does indeed use de.hdodenhof.circleimageview.CircleImageViewBerkman
M
0

This code help me:

Glide.with(view.getContext())
                .load(url)
                .placeholder(AppCompatResources.getDrawable(view.getContext(), R.drawable.vector_placeholder_vendor_image_crop))
                .dontAnimate()
                .into(view);

//need add .dontAnimate()

For more information: https://github.com/bumptech/glide/issues/1026#issuecomment-191709837

Maundy answered 20/7, 2018 at 5:59 Comment(1)
While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.Brezhnev
N
-2

First Time glide is unable to load image on custom view like circular Imageview.you Can use error to load image on first time.

The following snippet should help you:

 Glide.with(context)
         .load(imgUrl)
         .crossFade()
         .override(imageWidth,imageHeight).error(R.drawable.yourdrawable)
         .into(imgView);
Nifty answered 14/7, 2017 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.