The blog has not been updated for nearly one months, and because of all the things that have been going on in preparation for graduation theses, there has been no time and energy to sink in and keep on learning and organizing something. Just back on track recently, just two days to see the android on the image of the asynchronous loading of open source projects, by the way to record, as the one months to reopen the blog to cook. From today onwards I will resume the blog update, but also hope that we continue to support.
What we're going to introduce today is a very broad picture of GitHub using an asynchronous load library Android-universal-image-loader, which is a very powerful project that I've ever seen, the most complete and best-performing image asynchronous loading solution. Do Android students know, Android loading a lot of pictures, because the system assigned to the image load memory size is limited, so if the load picture is very large, it is easy to report Oom exception, about this exception has a lot of solutions, I do not repeat. The following is a brief introduction to the main features and use of this open source project:
I. SUMMARY of functions
- Multi-threaded picture loading;
- Flexibility to change the basic configuration of the Imageloader, including the maximum number of threads, cache mode, picture display options, etc.;
- Picture asynchronous load caching mechanism, including memory cache (soft reference) and local cache;
- Monitoring and event processing for loading process;
- Ability to configure display options for loading images, including picture fillet processing and loading complete display animations;
Second, basic use
- Download the jar package Universal-image-loader-1.8.5-with-sources.jar and import the project (this should not be taught)
- Configure the manifest file to add network requests and access to external storage because network requests and local caching are required
[HTML]View Plaincopy
- <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" />
3. Implement the Custom MyApplication class and initialize the Imageloader, note the application tag in the manifest to indicate
Android:name= ". MyApplication ", otherwise the default application class is used.
[Java]View Plaincopy
- Public class MyApplication extends application {
- @Override
- public void OnCreate () {
- super.oncreate ();
- //This configuration tuning is custom. You can tune every option, your may tune some of them,
- //or you can create the default configuration by
- //Imageloaderconfiguration.createdefault (this);
- //method.
- imageloaderconfiguration config = new Imageloaderconfiguration.builder (Getapplicationcontext ())
- . threadpriority (Thread.norm_priority- 2)
- . Denycacheimagemultiplesizesinmemory ()
- . Disccachefilenamegenerator (new Md5filenamegenerator ())
- . Tasksprocessingorder (Queueprocessingtype.lifo)
- . enableLogging () //Not necessary in common
- . build ();
- //initialize imageloader with configuration
- Imageloader.getinstance (). init (config);
- }
- }
4. Configure the picture loading and display options, here are a variety of custom configuration options, you can view the doc documentation to understand, here do not repeat (too much)
[Java]View Plaincopy
- Displayimageoptions options = new Displayimageoptions.builder ()
- . Showstubimage (R.drawable.ic_launcher)
- . Showimageforemptyuri (R.drawable.ic_launcher)
- . Showimageonfail (R.drawable.ic_launcher)
- . Cacheinmemory (true)
- . Cacheondisc (false)
- . Displayer (new Roundedbitmapdisplayer)
- . build ();
5. Load the picture using Imageloader, here to load the image asynchronously for each item in the ListView, as long as the following method is called in the adapter GetView method to complete the asynchronous list picture loading, The options are the previously defined picture loading and display option, Animatefirstlistener is the first time the picture is loaded for the listener event, with the aim of displaying a fade-in display animation that can add other events
- In addition, this example also realizes that when the list is suspended during the slide and the user's hands are released, the function of loading will not occur when the list image is loaded asynchronously, so as to ensure the smoothness of loading. The way to do this is to enable the ListView to listen for a listener event pauseonscrolllistener that is contained by Imageloader.
- If you set Cacheondisc (true), the cached file can be seen in the/sdcard/android/data/[package_name]/cache directory. However, it is recommended to periodically clean up the cache, otherwise the time is long, the SD card will be full, but also can be configured in the Imageloaderconfiguration SD cache policy, there are limits on the number of cache files, there is limited cache file maximum size options.
- If you encounter an Oom exception during use, it is recommended that you set ThreadPoolSize in imageloaderconfiguration to fit between 1-5. Used when the displayoption is configured.
Third, the demo effect
The following is the demo home page, which provides three kinds of components to display the multi-graph asynchronous loading way:
The following are the ListView and GridView as well as the Viewpager load display, the loading effect is very smooth:
above is just a brief introduction to the Imageloader features and usage overview, the implementation code can see the original link and download my Project Code view, more information please refer to the Official document: Click to open the link
Project download: Project source Cloud disk Download: Http://pan.baidu.com/s/1jGJYTMY Android pictures Asynchronous loading of the Android-universal-image-loader from the source of the collection network, reproduced please specify the source/HTTP/ www.codesocang.com/jiaocheng/shoujikaifa/8077.html