http://blog.csdn.net/king_is_everyone/article/details/34107081
Recently with the students to do a business project, in fact, with the previous project is different, most of the previous is to do Web site, memory management These are not too concerned about, because it is a PC, do Android words are some small examples, now to do product stage bar, only the project to achieve the best. No, first of all, what is the framework for, Android-universal-image-loader is primarily a picture caching framework, according to the official explanation, it provides a scheme for handling images asynchronously. It offers two ways to get pictures in async or sync, and provides a customizable component (thread executors, downloader, decoder, memory and disk cache, display image option s, etc), it will first cache the pictures locally and then read them locally,
It's officially used.
First of all, how to use it: First download Android-universal-image-loader on GitHub, add it to your Android project, and then remember to add these two permissions, otherwise this caching framework is not able to use
[HTML]View Plaincopyprint?
- <manifest>
- <uses-permission android:name="Android.permission.INTERNET" />
- <!--Include Next permission if you want to allow UIL to the cache images on SD card --
- <uses-permission android:name="Android.permission.WRITE_EXTERNAL_STORAGE" />
- ...
- <application android:name="MyApplication">
- ...
- </Application>
- </manifest>
The caching framework is then configured in code so that it is a very flexible thing because most of its parameters can be manually configured, the components are generalized to a high degree, and there is little need for replication.
This is I probably according to the official document translation of some configuration, in fact, for everyone, with the default, unless there are special requirements.
First steps to start using:
Configure imageloaderconfiguration This class to implement global Imageloader
[Java]View Plaincopyprint?
- imageloaderconfiguration config = new Imageloaderconfiguration.builder (
- Activity
- . Memorycacheextraoptions (640, 480)
- //Save the maximum length and width of each cached picture
- . ThreadPoolSize (3)
- //thread pool size This is actually the default is 3
- . memorycachesize (2 * 1024x768)
- //Set maximum bytes for cache
- . Denycacheimagemultiplesizesinmemory ()
- //cache Displays the same picture of different sizes
- . Imagedownloader (
- new Baseimagedownloader (activity, 5 * , + )) //ConnectTimeout
- //s) time-out
- . build ();
- Imageloader Imageloader = Imageloader.getinstance ();
- Imageloader.init (config);
Here are some of the parameter configurations that I probably need.
Step Two
Configure some picture options
[Java]View Plaincopyprint?
- Displayimageoptions options;
- options = new Displayimageoptions.builder ()
- . showimageonloading (R.drawable.ic_launcher) //Set picture to display during download
- . Showimageforemptyuri (R.drawable.ic_launcher)//Set picture to display when the image URI is empty or wrong
- . Showimageonfail (R.drawable.ic_launcher) //Set picture to be displayed during image loading/decoding error
- . Cacheinmemory (True)//Set whether the downloaded picture is slow to exist in memory
- . Cacheondisk (True)//Set whether the downloaded picture is slow to exist on the SD card
- . Displayer (new Fadeinbitmapdisplayer)//Whether the animation time after the picture is loaded and gradually entering
- . build ();
This is probably a configuration condition, and the next one will use a ListView instance to explain the specifics of the framework.
Android Picture Cache frame Android-universal-image-loader