Android-Universal-Image-Loader for asynchronous loading of Android Images,

Source: Internet
Author: User

Android-Universal-Image-Loader for asynchronous loading of Android Images,

I haven't updated my blog for nearly a month. Due to the troubles in preparing my graduation thesis and other affairs over this period of time, I have never had time and energy to study and sort out some things. I just got back to the right track recently. I just read the open-source project about asynchronous image loading on Android over the past two days, and I will record it by the way, as a blog for more than a month, Let's cook again. From today on, I will resume blog updates and hope you will continue to support them.

Today, we will introduce a widely used asynchronous Image loading library Android-Universal-Image-Loader on Github. This project has very powerful functions, it can be said that I have seen the most comprehensive and optimal image asynchronous loading solution. Android users know that when Android loads a large number of images, the memory size allocated by the system to the image loading is limited. Therefore, if the image loading volume is very large, it is easy to report an OOM exception, there are already many solutions for this exception, so I will not go into details. The following describes the main functions and usage of this open-source project:

 

I. Function Overview

 

  • Multi-threaded image loading;
  • You can flexibly change the basic configurations of ImageLoader, including the maximum number of threads, cache mode, and image display options;
  • Asynchronous image loading cache mechanism, including memory cache (soft reference) and local cache;
  • Implements monitoring and event processing for the loading process;
  • Allows you to configure the display options for loading images, including image rounded corner processing and display animation loading;
Ii. Basic use [Html]View plaincopy
  1. <Uses-permission android: name = "android. permission. INTERNET"/>
  2. <! -- Include next permission if you want to allow UIL to cache images on SD card -->
  3. <Uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/>

 

3. Implement the custom MyApplication class and initialize ImageLoader. Note that you must specify

Android: name = ". MyApplication". Otherwise, the default Application class is used.

 

[Java]View plaincopy
  1. Public class MyApplication extends Application {
  2. @ Override
  3. Public void onCreate (){
  4. Super. onCreate ();
  5. // This configuration tuning is custom. You can tune every option, you may tune some of them,
  6. // Or you can create default configuration
  7. // ImageLoaderConfiguration. createDefault (this );
  8. // Method.
  9. ImageLoaderConfiguration config = new ImageLoaderConfiguration. Builder (getApplicationContext ())
  10. . ThreadPriority (Thread. NORM_PRIORITY-2)
  11. . DenyCacheImageMultipleSizesInMemory ()
  12. . DiscCacheFileNameGenerator (new Md5FileNameGenerator ())
  13. . TasksProcessingOrder (QueueProcessingType. LIFO)
  14. . EnableLogging () // Not necessary in common
  15. . Build ();
  16. // Initialize ImageLoader with configuration
  17. ImageLoader. getInstance (). init (config );
  18. }
  19. }


4. Configure image loading and display options. There are a variety of custom configuration options here. You can refer to the doc documentation for details. I will not go into details here (too much)

 

 

[Java]View plaincopy
  1. DisplayImageOptions options = new DisplayImageOptions. Builder ()
  2. . ShowStubImage (R. drawable. ic_launcher)
  3. . ShowImageForEmptyUri (R. drawable. ic_launcher)
  4. . ShowImageOnFail (R. drawable. ic_launcher)
  5. . CacheInMemory (true)
  6. . CacheOnDisc (false)
  7. . Displayer (new RoundedBitmapDisplayer (20 ))
  8. . Build ();

 

5. use ImageLoader to load images. Here, the asynchronous image loading for each item in ListView is used as an example. As long as the following method is called in the getView method of the Adapter, the asynchronous list image loading is completed, options is the previously defined image loading and display options, and animateFirstListener is the listening event when the image is loaded for the first time. It aims to display a light display effect animation and add other events.

  • In addition, this example also implements the function of pausing loading and starting loading only when the user opens the list Sliding Process, this ensures that the asynchronous loading of list images is not choppy and smooth. This function enables ListView to listen to a monitoring event PauseOnScrollListener contained by ImageLoader.
  • If cacheOnDisc (true) is set, the cached files can be viewed in the/sdcard/Android/data/[package_name]/cache directory. However, it is recommended to clear the cache regularly. Otherwise, the SD card will be full after a long period of time. You can also configure the SD Cache Policy in ImageLoaderConfiguration to limit the number of cached files, the maximum size of cached files is limited.
  • If an OOM exception occurs during use, we recommend that you set threadPoolSize between 1 and 5 in ImageLoaderConfiguration. Used in DisplayOption configuration.

Iii. Demo Effect

The Demo homepage provides three methods for Displaying Multiple Graphs asynchronously:

 

The following shows how ListView, GridView, and ViewPager are loaded smoothly:


The above section briefly introduces the functions and usage of ImageLoader. For specific implementation code, you can view the original link and download my project code. For details, see the official documentation: Click the open link.
Project download: Project source cloud disk download: http://pan.baidu.com/s/1jGJYTMY Android pictures asynchronously loaded Android-Universal-Image-Loader by the source code search collection network, reprinted please indicate the source http://www.codesocang.com/jiaocheng/shoujikaifa/8077.html




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.