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 IMA GE options, etc), which caches images first locally and then reads 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
<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.permis Sion. 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
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 * 1024)// Sets the maximum number of bytes for the cache. Denycacheimagemultiplesizesinmemory ()//cache Displays the same picture of different sizes. Imagedownloader (New Baseimagedownloader ( Activity, 5 * (+)))//connecttimeout//s) timeout time. build (); Imageloader Imageloader = Imageloader.getinstance (); IMA Geloader.init (config);
Here are some of the parameter configurations that I probably need.
Step Two
Configure some picture options
Displayimageoptions options;options = new Displayimageoptions.builder (). showimageonloading (R.drawable.ic_launcher) Sets the picture that the picture displays during the download. Showimageforemptyuri (R.drawable.ic_launcher)//Set the picture URI to be displayed when it is empty or wrong. Showimageonfail ( R.drawable.ic_launcher)//Set the picture to be displayed when the image is loaded/decoded in error. Cacheinmemory (TRUE)//sets whether the downloaded picture is in memory. Cacheondisk (TRUE)// Sets whether the downloaded picture is slow to exist on the SD card. Displayer (new Fadeinbitmapdisplayer (100))//Whether the picture is loaded and the animation time is gradually entered. build ();
This is probably a configuration condition, and the next one will use a ListView instance to explain the specifics of the framework.