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!

Sam Judd
  • 7,317
  • 1
  • 38
  • 38
oznus
  • 2,446
  • 2
  • 25
  • 18

6 Answers6

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

Sagar
  • 5,273
  • 4
  • 37
  • 50
  • 1
    If you use `de.hdodenhof.circleimageview.CircleImageView` you'll need to add `dontAnimate()` as shown on this answer – Albert Vila Calvo Feb 25 '19 at 08:39
  • 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 me – Archid Jun 24 '21 at 07:25
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.

BladeCoder
  • 12,779
  • 3
  • 59
  • 51
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);
oznus
  • 2,446
  • 2
  • 25
  • 18
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);
Wasim K. Memon
  • 5,979
  • 4
  • 40
  • 55
  • 1
    `.dontAnimate()` adding this to `Glide` solved my problem. thanks – Sagar Sep 03 '18 at 12:53
  • 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 :/ – Albert Vila Calvo Feb 22 '19 at 10:47
  • @AlbertVilaCalvo the problem is with circular image view please check the the answer I have posted below. – Sagar Feb 25 '19 at 04:48
  • Thanks @Sagar the project I'm working on does indeed use `de.hdodenhof.circleimageview.CircleImageView` – Albert Vila Calvo Feb 25 '19 at 08:38
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

  • 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. – Alex Riabov Jul 20 '18 at 06:17
-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);
Markus
  • 2,071
  • 4
  • 22
  • 44