Glide in Android loads pictures and implements picture caching

Today, I encountered the cache problem of glide in my work. I used glide to load local and network pictures in the project before, but I didn't consider the cache problem, but it needs to be mentioned in the requirements, so I checked it online, and then I'll briefly share with you the usage method and cache of glide. First, glide is an open-source picture library on GitHub, The author is bumptech, so to use it, you must add dependencies:

Loading method:

The loading method is very simple. Load loads the URL and into binds the control. Context, which supports activity and fragment and is consistent with the life cycle of the activity, pauses loading in onpause() and resumes loading in onresume()

Second, it's not just that:

Glide can also set loading animation through crossfade(), placeholder() loads images by default, error() loads error images, etc. in addition, it also supports image boundary scaling, such as centercrop and fitcenter

Finally, glide supports image caching

Adding diskcachestrategy (diskcachestrategy. All) supports hard disk caching. Because glide hard disk cache will cache the same picture with different width and height twice, diskcachestrategy.all needs to be set. It will take out the full-size pictures when loading next time and cache them according to the set size.

If you don't want to read from the cache, glide also provides a skipmemorycache (Boolean) method. Do you want to skip the cache? Ha ha, is it complete?

The above are some simple ways to use glide for reference only.

Of course, glide can also set the size, path, format, etc

1 create glidemodule

2 add the meta data tag tag tag in the manifest file

3 confusion

4 set hard disk cache size

5 set cache location

You can use the built-in internalcachediskcachefactory to place your cache in the internal cache directory of the application:

You can also use the built-in external cachediskcachefactory to place your SD card in the public cache directory of the application:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>