Android image caching technology in direct application project

Android image caching, which was launched not long ago, has just introduced an open source framework, which is OK. However, there are problems in development, such as universal-image-loader-1.9.5.jar. When loading images, the custom ImageView cannot be loaded. There may be the following problems. In addition, the import of the framework leads to the development of larger and larger project packages, Based on the above situations, I want to write a three-level image cache tool myself. Brief analysis: at the beginning, I thought that the loading and display of pictures is nothing more than checking whether there is in the memory, looking in the file if there is no in the file, and starting the network download if there is no in the file. This also meets most of the requirements in the development, and the efficiency must be higher, In some cases, such as fast sliding listview, loading pictures from files is not as fast as loading pictures from memory. Let's see the effect first! This is the first picture loaded, of course, an online picture:

The picture is loaded. We need to look at the log. The log won't lie. I'll take a screenshot of the log

Just now, there was no local or memory, so I went to the network to download. All logs are printed to start the network download. However, when I enter the application for the second time? Go back and start the network download? It certainly won't. what's the use of asking for it like this? Look, this is the log when you enter the application for the second time

Loading pictures from a file no longer requires you to open the network download and get them directly from the file. Well, this problem comes. Reading from a file must be inefficient. It doesn't read directly from memory. Come on! We call an algorithm maintained by the system. Recently, we use the least algorithm. This algorithm was learned when I was learning the operating system. The teacher talked about it at that time, but fortunately, we can use what the teacher said in the project. For this, I think it's over? We should read the pictures in the file into memory to prevent dislocation bugs caused by fast sliding such as listview. Let's see what I do when I slide quickly:

The loaded pictures are obtained from memory, so the effect is very good! OK, how to implement such a good image level 3 cache and how to use it? Now post the code I wrote! Let's have a look and optimize it by the way!

The following is a demo, which is actually very simple

Let's introduce it to you. Let's digest it slowly. I hope the article will help you more or less.

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