Android Open source Framework Universal-image-loader

Source: Internet
Author: User

First look at the effect
Frame Features
    1. Multi-threaded download pictures, images can be from the network, file system, project folder assets and drawable medium
    2. Supports arbitrary configuration of imageloader, such as thread pool, picture downloader, memory cache policy, hard disk cache policy, picture display options, and other configuration
    3. Memory cache for image support, file system cache or SD card cache
    4. Support for monitoring the image download process
    5. Bitmap is clipped based on the size of the control (ImageView), reducing bitmap memory consumption
    6. Better control of the loading process of the picture, such as pause picture loading, restart loading pictures, generally used in the Listview,gridview, the sliding process to pause loading pictures, stop the slide when to load the picture
    7. Provides loading of pictures on a slower network
1. Customizing the Xxxappllication class, initializing the Imageloader
public class Xxxapplication extends application {@Overridepublic void OnCreate () {super.oncreate ();        imageloaderconfiguration config = new Imageloaderconfiguration.builder (Getapplicationcontext ())        . Denycacheimagemultiplesizesinmemory ()        . MemoryCache (New Lrumemorycache (2 * 1024x768))        . Memorycachesize (2 * * 1024x768).        disccachesize (* 1024x768).        denycacheimagemultiplesizesinmemory ().              Disccachefilenamegenerator (New Md5filenamegenerator ())              . Tasksprocessingorder (QUEUEPROCESSINGTYPE.LIFO)          . Disccachefilecount (+).        writedebuglogs ()            . Build ();        Imageloader.getinstance (). init (config);}}

2. In the Application tab of the Androidmanifest.xml file, add
Android:name= ". Xxxapplication "

3. Using Imageloader
public class imagemanager{public static void Load (String imgurl,imageview ImageView) {imageloader.getinstance (). DisplayImage (Imgurl, ImageView); public static void Load (String imgurl,imageview imageview,displayimageoptions o) {imageloader.getinstance (). DisplayImage (Imgurl, imageview,o); }}
4. Some parameter introduction (displayimageoptions)
     Set picture to display during download showstubimage (r.drawable.ic_launcher)//Set picture Showimageforemptyuri When image uri is empty or wrong (r.dr Awable.ic_empty)//Set Picture Showimageonfail (R.drawable.ic_error)//Set image to reset before downloading, reset Resetvie before loading/decoding     Wbeforeloading ()//Set whether the downloaded picture is slow to exist in memory cacheinmemory ()//Set the downloaded picture is slow to exist in SD card Cacheondisc ()//Set the decoded type of picture Bitmapconfig (Bitmap.Config.RGB_565)//Set the decoding configuration of the picture decodingoptions (Android.graphics.BitmapFactory.Options Decodingo ptions)//Set the delay delaybeforeloading (int delayinmillis) before the picture is downloaded//Set additional content to Imagedownloader Extrafordownloader (     Object extra)//set the picture before adding the cache, set the bitmap to preprocessor (bitmapprocessor preprocessor)//Set the picture before the display, the picture remains in the cache Postprocessor (Bitmapprocessor postprocessor)//Set the picture in how to encode Imagescaletype (Imagescaletype imagescaletype)/* * * Set how the image is displayed * @param displayer */displayer (bitmapdisplayer displayer) displayer:roundedbitmapdisplayer (int Roun          Dpixels) Set the fillet pictureFakebitmapdisplayer () This class does nothing fadeinbitmapdisplayer (int durationmillis) sets the time of the picture Fade Simplebitmapdisplayer () normally displays a                   Picture/** * How the image is scaled * @param imagescaletype */imagescaletype (Imagescaletype imagescaletype) Imagescaletype: Exactly: The image will be fully scaled to the target size exactly_stretched: The picture zooms to the target size completely in_sample_int: The image will be two times Sampled integer multiples in_sample_power_of_2: The picture will be lowered twice times until the next reduction step, making the image smaller than the target size NONE: Picture does not adjust/***displayimageopt Ions Simple example *///create the default displayimageoptionsdisplayimageoptions option_0=displayimageoptions.createsimple ();// Use Displayimageoptions.builder () to create displayimageoptionsdisplayimageoptions options = new Displayimageoptions.builder ( ). Imagescaletype (imagescaletype.exactly_stretched). Showstubimage (r.drawable.loading). ShowImageForEmptyUri (  R.drawable.load_fail). Showimageonfail (R.drawable.load_fail). Cacheinmemory (True). Cacheondisc (True). Build ();

5. Don't forget permissions at the end
    <uses-permission android:name= "Android.permission.INTERNET"/>    <uses-permission android:name= " Android.permission.WRITE_EXTERNAL_STORAGE "/>    <uses-permission android:name=" android.permission.MOUNT_ Unmount_filesystems "/>
SOURCE download

Android Open source Framework 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.