国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android Imageloader的配置的實現代碼

2019-10-22 18:31:44
字體:
來源:轉載
供稿:網友

Android Imageloader的配置的實現代碼

  ImageLoader 優點

(1) 支持下載進度監聽

(2) 可以在 View 滾動中暫停圖片加載

通過 PauseOnScrollListener 接口可以在 View 滾動中暫停圖片加載。

(3) 默認實現多種內存緩存算法 這幾個圖片緩存都可以配置緩存算法,不過 ImageLoader 默認實現了較多緩存算法,如 Size

最大先刪除、使用最少先刪除、最近最少使用、先進先刪除、時間最長先刪除等。

(4) 支持本地緩存文件名規則定義     

實現代碼:

/**  * 初始化ImageLoader  */ public static void initImageLoader(Context context) {   File cacheDir = StorageUtils.getOwnCacheDirectory(context,       "bee_k77/Cache");// 獲取到緩存的目錄地址   Log.e("cacheDir", cacheDir.getPath());   // 創建配置ImageLoader(所有的選項都是可選的,只使用那些你真的想定制),這個可以設定在APPLACATION里面,設置為全局的配置參數   ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(       context)       // max width, max height,即保存的每個緩存文件的最大長寬       .memoryCacheExtraOptions(480, 800)       // Can slow ImageLoader, use it carefully (Better don't use it)設置緩存的詳細信息,最好不要設置這個 /        .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75, null)        // 線程池內加載的數量       .threadPoolSize(3)       // 線程優先級       .threadPriority(Thread.NORM_PRIORITY - 2)       /*        * When you display an image in a small ImageView        * and later you try to display this image (from identical URI) in a larger ImageView        * so decoded image of bigger size will be cached in memory as a previous decoded image of smaller size.        * So the default behavior is to allow to cache multiple sizes of one image in memory.        * You can deny it by calling this method:        * so when some image will be cached in memory then previous cached size of this image (if it exists)        *  will be removed from memory cache before.        */ /        .denyCacheImageMultipleSizesInMemory()              // You can pass your own memory cache implementation你可以通過自己的內存緩存實現       // .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))        // .memoryCacheSize(2 * 1024 * 1024)       //硬盤緩存50MB       .diskCacheSize(50 * 1024 * 1024)        //將保存的時候的URI名稱用MD5       .diskCacheFileNameGenerator(new Md5FileNameGenerator())       // 加密        .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())//將保存的時候的URI名稱用HASHCODE加密       .tasksProcessingOrder(QueueProcessingType.LIFO)        .diskCacheFileCount(100) //緩存的File數量       .diskCache(new UnlimitedDiscCache(cacheDir))// 自定義緩存路徑       // .defaultDisplayImageOptions(DisplayImageOptions.createSimple())       // .imageDownloader(new BaseImageDownloader(context, 5 * 1000,       // 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超時時間       .writeDebugLogs() // Remove for release app       .build();   // Initialize ImageLoader with configuration.   ImageLoader.getInstance().init(config);// 全局初始化此配置 } 

Option類

package com.topnews.config;  import android.graphics.Bitmap;  import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.assist.ImageScaleType; import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; import com.topnews.R;  public class Options {   /**    * 新聞列表中用到的圖片加載配置    */   public static DisplayImageOptions getListOptions() {     DisplayImageOptions options = new DisplayImageOptions.Builder()     // 設置圖片在下載期間顯示的圖片         .showImageOnLoading(R.drawable.ic_stub)         // 設置圖片Uri為空或是錯誤的時候顯示的圖片         .showImageForEmptyUri(R.drawable.ic_stub)         // 設置圖片加載/解碼過程中錯誤時候顯示的圖片         .showImageOnFail(R.drawable.ic_error)         // 設置下載的圖片是否緩存在內存中         .cacheInMemory(false)         // 設置下載的圖片是否緩存在SD卡中         .cacheOnDisc(true)         // 保留Exif信息         .considerExifParams(true)         // 設置圖片以如何的編碼方式顯示         .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)         // 設置圖片的解碼類型         .bitmapConfig(Bitmap.Config.RGB_565)         // .decodingOptions(android.graphics.BitmapFactory.Options         // decodingOptions)//設置圖片的解碼配置         .considerExifParams(true)         // 設置圖片下載前的延遲         .delayBeforeLoading(100)// int         // delayInMillis為你設置的延遲時間         // 設置圖片加入緩存前,對bitmap進行設置         // .preProcessor(BitmapProcessor preProcessor)         .resetViewBeforeLoading(true)// 設置圖片在下載前是否重置,復位         // .displayer(new RoundedBitmapDisplayer(20))//是否設置為圓角,弧度為多少         .displayer(new FadeInBitmapDisplayer(100))// 淡入         .build();     return options;   } } 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大余县| 常德市| 高邑县| 东光县| 鄯善县| 钟祥市| 嘉荫县| 玉门市| 乌拉特前旗| 凤山市| 沈阳市| 汕头市| 壤塘县| 政和县| 盱眙县| 安图县| 梅河口市| 嘉黎县| 团风县| 太仆寺旗| 通河县| 通州市| 长宁县| 鄂温| 乌鲁木齐市| 将乐县| 崇阳县| 图片| 平顶山市| 仁布县| 天门市| 福泉市| 泗水县| 昂仁县| 池州市| 正宁县| 福贡县| 甘肃省| 精河县| 仁化县| 清丰县|