ImageLoader image loading framework

1_ Features
1) multi-threaded download pictures, pictures can be from the network, file system, the project folder in assets and drawable
Medium
2) support random configuration ImageLoader, such as thread pool, picture downloads, memory caching strategy, hard disk cache
memory strategy, the picture display options as well as some other configuration
3) supported picture memory caching, file system cache or SD card cache
4) support listening picture download process
5) of the Bitmap cut according to the size of the controls (ImageView), reducing Bitmap occupancy excessive memory
6) better control the loading process images, such as image loading pause, resume load picture, generally used in the
ListView, GridView, the sliding load images during the pause, when to stop sliding load picture
7) to provide the picture is loaded at a slower network

2_ Download
https://github.com/nostra13/Android-Universal-Image-Loader

Step 3_ use

1) Import universal-image-loader-1.9.5.jar to the project
2) create MyApplication inherited Application, in oncreate () to initialize ImageLoader
(1) initialization ImageLoaderConfiguration

 // initialization parameter 
 ImageLoaderConfiguration config = new new ImageLoaderConfiguration.Builder (context) .threadPriority (Thread.NORM_PRIORITY - 2 )
     // thread priority level          
    .denyCacheImageMultipleSizesInMemory ()
     // When Uri get the same picture different size, cache memory, only a cache. Default cache multiple different sizes of the same picture 
    .discCacheFileNameGenerator ( new new Md5FileNameGenerator ())
     // URI of the name is saved when using MD5 
    .tasksProcessingOrder (QueueProcessingType.LIFO)
     // set the image to download and display the work queue ordering 
    .writeDebugLogs ()
     // Print log Debug 
    .build ();

(2) ImageLoader Global 

 // global initialization configuration 
 ImageLoader.getInstance () init (config). ;

 

(3) complete code 

public class MyApplication extends Application {

   @Override
   public void onCreate() {
       super.onCreate();
       initImageLoader(this);
   }

   // 初始化 imageloader     
   private void initImageLoader(Context context) { 
    // 初始化参数         
       ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPriority(Thread.NORM_PRIORITY - 2)
       // 线程优先级                 
       .denyCacheImageMultipleSizesInMemory()
       //When Uri get with a different size image, a cache memory, a cache only. Default cache multiple different sizes of the same picture                  
       .discCacheFileNameGenerator ( new new Md5FileNameGenerator ()) // URI of the name is saved when using MD5 
       .tasksProcessingOrder (QueueProcessingType.LIFO)
        // set the image to download and display the work queue ordering                 
       .writeDebugLogs ()
        // print log Debug                  
       Build (); 
        } 
    }

3) created MyApplication registered in AndroidManifest.xml 

4) add networking permissions and write permissions in AndroidManifest.xml sdk 

<uses-permission android:name="android.permission.INTERNET">
</uses-permission> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permiss ion>

5) initialization DisplayImageOptions 

Options = DisplayImageOptions new new DisplayImageOptions.Builder (). ShowStubImage (R.drawable.ic_stub)
     // pictures displayed during picture download settings 
    .showImageForEmptyUri (R.drawable.ic_empty)
     // set the image Uri is empty or is the wrong time to be displayed pictures 
    .showImageOnFail (R.drawable.ic_error)
     // set the image to load or picture display error occurs in the decoding process 
    .cacheInMemory ( to true )
     // set to download images if the cache in memory 
    .cacheOnDisk ( to true )
     // set to download images are cached SD card 
    .displayer ( new new RoundedBitmapDisplayer ( 20 ))
     // set rounded picture 
    .build ();
  

6) Get ImageLoader Example 

private ImageLoader imageLoader = ImageLoader.getInstance(); 

7) shows the loading of images 

// Parameter 1: Image url; Parameter 2: image display control; 3 parameters: the picture display settings; Parameter 4: listener 
imageLoader.displayImage (Constants.IMAGES [position], holder.image , options, mFirstLoadImageListener);

 

Guess you like

Origin www.cnblogs.com/yanglanwan/p/11299306.html