Preload multiple images with Glide

后端 未结 5 969
我寻月下人不归
我寻月下人不归 2020-11-30 02:07

We are trying to preload images into cache memory to load them later (the images are located in the Asset folder of the application)

<
5条回答
  •  北海茫月
    2020-11-30 02:26

    Use the following code to cache images without displaying them

    1. using the downloadOnly method if you are looking to download images from the web and store them in the diskCache:

      FutureTarget future = Glide.with(applicationContext)
          .load(yourUrl)
          .downloadOnly(500, 500);
      
    2. using preload method if you want to load them into the Memory Cache.

      Glide.with(context)
              .load(url)
              .preload(500, 500);
      

    You can later use the cached images using

    Glide.with(yourFragment)
        .load(yourUrl)
        .into(yourView);
    

提交回复
热议问题