Loading pictures from Android L2 cache to realize photo wall function

To realize the function of loading pictures from the secondary cache, when using disklrucache, you need to first add a package named libcore.io in the project and put the disklrucache.java file in it. Disklrucache can be downloaded directly from Baidu.

In the adapter of GridView, when adding pictures to ImageView, first load them from the memory cache. If there is no cache in memory, load them in the disk cache. If there is no disk cache, start the thread to download, and then cache the downloaded pictures to the disk and memory. It is best to compress the downloaded pictures first. The compression code is given at the end of the article, but compression is not realized in this example.

/*The secondary cache implements the picture wall function. First, load the cache in memory. If there is no cache in memory, load it in the disk cache. If there is still no cache, start the thread to download the picture, download it, cache it in disk, and then cache it in memory*/

MainActivity

Layout of main activity

Item ImageView in GridView

Image compression implementation

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
分享
二维码
< <上一篇
下一篇>>