universal-image-loader 配置

[java] view plain copy
 print?在CODE上查看代碼片派生到我的代碼片
  1. /** 
  2.  * 初始化ImageLoader 
  3.  */  
  4. public static void initImageLoader(Context context) {  
  5.     File cacheDir = StorageUtils.getOwnCacheDirectory(context,  
  6.             "bee_k77/Cache");// 獲取到緩存的目錄地址  
  7.     Log.e("cacheDir", cacheDir.getPath());  
  8.     // 創建配置ImageLoader(所有的選項都是可選的,只使用那些你真的想定製),這個可以設定在APPLACATION裏面,設置爲全局的配置參數  
  9.     ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(  
  10.             context)  
  11.             // max width, max height,即保存的每個緩存文件的最大長寬  
  12.             .memoryCacheExtraOptions(480800)  
  13.             // Can slow ImageLoader, use it carefully (Better don't use it)設置緩存的詳細信息,最好不要設置這個  
  14. /                .discCacheExtraOptions(480800, CompressFormat.JPEG, 75null)   
  15.             // 線程池內加載的數量  
  16.             .threadPoolSize(3)  
  17.             // 線程優先級  
  18.             .threadPriority(Thread.NORM_PRIORITY - 2)  
  19.             /* 
  20.              * When you display an image in a small ImageView 
  21.              *  and later you try to display this image (from identical URI) in a larger ImageView  
  22.              *  so decoded image of bigger size will be cached in memory as a previous decoded image of smaller size. 
  23.              *  So the default behavior is to allow to cache multiple sizes of one image in memory.  
  24.              *  You can deny it by calling this method:  
  25.              *  so when some image will be cached in memory then previous cached size of this image (if it exists) 
  26.              *   will be removed from memory cache before. 
  27.              */  
  28. /               .denyCacheImageMultipleSizesInMemory()  
  29.               
  30.             // You can pass your own memory cache implementation你可以通過自己的內存緩存實現  
  31.             // .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))   
  32.             // .memoryCacheSize(2 * 1024 * 1024)  
  33.             //硬盤緩存50MB  
  34.             .diskCacheSize(50 * 1024 * 1024)  
  35.              //將保存的時候的URI名稱用MD5  
  36.             .diskCacheFileNameGenerator(new Md5FileNameGenerator())  
  37.             // 加密  
  38.              .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())//將保存的時候的URI名稱用HASHCODE加密  
  39.             .tasksProcessingOrder(QueueProcessingType.LIFO)  
  40.              .diskCacheFileCount(100//緩存的File數量  
  41.             .diskCache(new UnlimitedDiscCache(cacheDir))// 自定義緩存路徑  
  42.             // .defaultDisplayImageOptions(DisplayImageOptions.createSimple())  
  43.             // .imageDownloader(new BaseImageDownloader(context, 5 * 1000,  
  44.             // 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超時時間  
  45.             .writeDebugLogs() // Remove for release app  
  46.             .build();  
  47.     // Initialize ImageLoader with configuration.  
  48.     ImageLoader.getInstance().init(config);// 全局初始化此配置  
  49. }  

Option類

[java] view plain copy
 print?在CODE上查看代碼片派生到我的代碼片
  1. package com.topnews.config;  
  2.   
  3. import android.graphics.Bitmap;  
  4.   
  5. import com.nostra13.universalimageloader.core.DisplayImageOptions;  
  6. import com.nostra13.universalimageloader.core.assist.ImageScaleType;  
  7. import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;  
  8. import com.topnews.R;  
  9.   
  10. public class Options {  
  11.     /** 
  12.      * 新聞列表中用到的圖片加載配置 
  13.      */  
  14.     public static DisplayImageOptions getListOptions() {  
  15.         DisplayImageOptions options = new DisplayImageOptions.Builder()  
  16.         // 設置圖片在下載期間顯示的圖片  
  17.                 .showImageOnLoading(R.drawable.ic_stub)  
  18.                 // 設置圖片Uri爲空或是錯誤的時候顯示的圖片  
  19.                 .showImageForEmptyUri(R.drawable.ic_stub)  
  20.                 // 設置圖片加載/解碼過程中錯誤時候顯示的圖片  
  21.                 .showImageOnFail(R.drawable.ic_error)  
  22.                 // 設置下載的圖片是否緩存在內存中  
  23.                 .cacheInMemory(false)  
  24.                 // 設置下載的圖片是否緩存在SD卡中  
  25.                 .cacheOnDisc(true)  
  26.                 // 保留Exif信息  
  27.                 .considerExifParams(true)  
  28.                 // 設置圖片以如何的編碼方式顯示  
  29.                 .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)  
  30.                 // 設置圖片的解碼類型  
  31.                 .bitmapConfig(Bitmap.Config.RGB_565)  
  32.                 // .decodingOptions(android.graphics.BitmapFactory.Options  
  33.                 // decodingOptions)//設置圖片的解碼配置  
  34.                 .considerExifParams(true)  
  35.                 // 設置圖片下載前的延遲  
  36.                 .delayBeforeLoading(100)// int  
  37.                 // delayInMillis爲你設置的延遲時間  
  38.                 // 設置圖片加入緩存前,對bitmap進行設置  
  39.                 // .preProcessor(BitmapProcessor preProcessor)  
  40.                 .resetViewBeforeLoading(true)// 設置圖片在下載前是否重置,復位  
  41.                 // .displayer(new RoundedBitmapDisplayer(20))//是否設置爲圓角,弧度爲多少  
  42.                 .displayer(new FadeInBitmapDisplayer(100))// 淡入  
  43.                 .build();  
  44.         return options;  
  45.     }  
  46. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章