Android Picture Cache frame Android-universal-image-loader

Source: Internet
Author: User

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?
  1. <manifest>
  2. <uses-permission android:name="Android.permission.INTERNET" />
  3. <!--Include Next permission if you want to allow UIL to the cache images on SD card --
  4. <uses-permission android:name="Android.permission.WRITE_EXTERNAL_STORAGE" />
  5. ...
  6. <application android:name="MyApplication">
  7. ...
  8. </Application>
  9. </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?
  1. imageloaderconfiguration config = new Imageloaderconfiguration.builder (
  2. Activity
  3. . Memorycacheextraoptions (640, 480)
  4. //Save the maximum length and width of each cached picture
  5. . ThreadPoolSize (3)
  6. //thread pool size This is actually the default is 3
  7. . memorycachesize (2 * 1024x768)
  8. //Set maximum bytes for cache
  9. . Denycacheimagemultiplesizesinmemory ()
  10. //cache Displays the same picture of different sizes
  11. . Imagedownloader (
  12. new Baseimagedownloader (activity, 5 * , + )) //ConnectTimeout
  13. //s) time-out
  14. . build ();
  15. Imageloader Imageloader = Imageloader.getinstance ();
  16. Imageloader.init (config);


Here are some of the parameter configurations that I probably need.

Step Two

Configure some picture options

[Java]View Plaincopyprint?
  1. Displayimageoptions options;
  2. options = new Displayimageoptions.builder ()
  3. . showimageonloading (R.drawable.ic_launcher) //Set picture to display during download
  4. . Showimageforemptyuri (R.drawable.ic_launcher)//Set picture to display when the image URI is empty or wrong
  5. . Showimageonfail (R.drawable.ic_launcher) //Set picture to be displayed during image loading/decoding error
  6. . Cacheinmemory (True)//Set whether the downloaded picture is slow to exist in memory
  7. . Cacheondisk (True)//Set whether the downloaded picture is slow to exist on the SD card
  8. . Displayer (new Fadeinbitmapdisplayer)//Whether the animation time after the picture is loaded and gradually entering
  9. . 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

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.