Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide loading images each time when scrolling recyclerview

I have a RecyclerView and each item of RecyclerView is having ImageView. I am loading the image in that ImageView using Glide, when I scroll down the RecyclerView it loads images and this is fine, but when I again srcoll up the RecyclerView it again loads those images which are already been loaded. I do not want to load that images again which have already been loaded.

I am using the below code to load images using Glide

Glide.with(mActivity)
                .load(img.getmGridViewImageUrl())
                .into(imageHolder.imageView);
like image 872
Prithniraj Nicyone Avatar asked Jan 25 '16 04:01

Prithniraj Nicyone


1 Answers

You can cache the images either on disk or in Memory.

By default images are cached in Memory by Glide

It's also good to know that Glide will put all image resources into the memory cache by default. Thus, a specific call .skipMemoryCache( false ) is not necessary.

If you want to enable cache in disk you can use one of the following

  1. DiskCacheStrategy.SOURCE caches only the original full-resolution image.
  2. DiskCacheStrategy.RESULT caches only the final image, after reducing the resolution (and possibly transformations)
  3. DiskCacheStrategy.ALL caches all versions of the image (default behavior)

Usage :

Glide  
    .with( context )
    .load( url )
    .diskCacheStrategy( DiskCacheStrategy.ALL )
    .into( imageViewInternet );
like image 72
Logic Avatar answered Oct 19 '22 21:10

Logic