Glide loads images every time you scroll through recycliewiew

I have a RecyclerView , and each RecyclerView element has an ImageView . I load the image into ImageView using Glide , when I scroll down the RecyclerView , it loads the images, and that's fine, but when I hide the RecyclerView again, it loads the images that are already loaded again. I do not want to download again these images that have already been downloaded.

I use the code below to upload images using Glide

 Glide.with(mActivity) .load(img.getmGridViewImageUrl()) .into(imageHolder.imageView); 
+5
source share
3 answers

You can cache images either on disk or in memory.

By default, images are cached in memory using Glide.

It's also good to know that Glide places all image resources in the cache cache by default. Thus, a special call to .skipMemoryCache (false) is not required.

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

  • DiskCacheStrategy.SOURCE caches only the original full resolution image.
  • DiskCacheStrategy.RESULT only caches the final image, after decreasing the resolution (and possibly conversion)
  • DiskCacheStrategy.ALL caches all versions of the image (default behavior)

Using:

 Glide .with( context ) .load( url ) .diskCacheStrategy( DiskCacheStrategy.ALL ) .into( imageViewInternet ); 
+6
source

after doing this diskCacheStrategy (DiskCacheStrategy.RESULT) I also see in the feeder that it is loading images from the network. I just scroll through the grid resizer view.

0
source

you cannot use this method directly, as shown below, I will work

 RequestOptions requestOptions = new RequestOptions(); requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL); Glide.with( context ) .load( imagesModelList.get(position).getUrl() ).apply(requestOptions) .into( holder.imageView ); holder.delete_item.setVisibility(View.VISIBLE); 
0
source

Source: https://habr.com/ru/post/1241382/


All Articles