Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image flickering when Glide loads it

I have a list of image views and some of them will be frequently updated with a fixed url. By appending a timestamp query parameter in the end of the url. It works, but I found when it updates it will also clear the current content. Any way to prevent this?

// the one needed to update with timestamp appended
image += "?"+String.valueOf(System.currentTimeMillis());
Glide.with(mContext.getApplicationContext())
        .load(image)
        .error(R.drawable.default_avatar)
        .centerCrop()
        .crossFade()
        .into(((VideoViewHolder) holder).img);

// the others don't need to update
Glide.with(mContext.getApplicationContext())
        .load(image)
        .error(R.drawable.default_avatar)
        .centerCrop()
        .crossFade()
        .into(((VideoViewHolder) holder).img);

Note that the others without timestamp appended are all good.

like image 745
Dayo Choul Avatar asked Nov 01 '17 11:11

Dayo Choul


People also ask

How do you optimize memory consumption when using Glide?

Loading images with the unknown size If a loaded image happens to be smaller than the ImageView, Glide will unnecessarily expand original bitmap to match the size of the target view. One way to prevent it is to set scaleType=”centerInside” in the ImageView. That way loaded image won't expand beyond the original size.

Does glide cache images Android?

Glide enables effective loading and caching of images. You can load images from a variety of sources such as files URIs, Android resources, bitmaps, drawables, etc. Just use the load() method to receive images. Image editing and more transformations.

How do you show pictures on Glide?

To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.

Can glide load videos?

Glide is a library for showing and caching images in android and it's not usable for videos.


1 Answers

Try this

Glide
.with(context)
.load(filepath)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.dontAnimate()
.into(new SimpleTarget<Bitmap>() {

        @Override
        public void onResourceReady(Bitmap arg0, GlideAnimation<? super Bitmap> arg1) {
            // TODO Auto-generated method stub
            holder.mItemView.setImageBitmap(arg0);
        }
    });

If you're using Glide 3.x and wish to directly display the image without the small crossfade effect, call .dontAnimate() on the Glide request builder: for more read this : Glide — Placeholders & Fade Animations

Happy coding!!

like image 152
Hemant Parmar Avatar answered Sep 20 '22 11:09

Hemant Parmar