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

首頁 > 學院 > 開發設計 > 正文

Image-Loader簡單使用

2019-11-09 16:39:33
字體:
來源:轉載
供稿:網友

一、Inage-Loader特性: 1、支持多線程下載圖片,圖片可以來源于網絡,文件系統,項目文件夾assets中以及drawable中等 2、支持自定義的配置,例如線程池,圖片下載器,內存緩存策略,硬盤緩存策略,圖片顯示選項等等 3、支持圖片的內存緩存,文件系統緩存或者SD卡緩存 4、支持圖片下載過程的監聽 5、根據控件(ImageView)的大小對Bitmap進行裁剪,減少Bitmap占用過多的內存 6、較好的控制圖片的加載過程,例如暫停圖片加載,重新開始加載圖片,一般使用在ListView,GridView中,滑動過程中暫停加載圖片,停止滑動的時候去加載圖片 7、提供在較慢的網絡下對圖片進行加載 二、使用方法: 1、創建ImageLoader,所有的操作都由ImageLoader控制。該類使用單例設計模式,所以如果要獲取該類的實例,需要調用getInstance()方法。在使用ImageLoader顯示圖片之前,你首先要初始化它的配置,調用ImageLoaderConfiguration的init()方法,ok了。

//創建ImageLoader ImageLoaderConfiguration config = ImageLoaderConfiguration .createDefault(mContext); ImageLoader.getInstance().init(config);// 全局初始化此配置

2、自定義配置,首先,需要使用ImageLoaderConfiguration對象來初始化ImageLoader。由于ImageLoader是單例,所以在程序開始的時候只需要初始化一次就好了。建議你在Baseapplication的onCreate()方法中初始化。如果一個ImageLoader已經初始化過,再次初始化不會有任何效果。下面我們通過ImageLoaderConfiguration.Builder創建:

File cacheDir =StorageUtils.getOwnCacheDirectory(this, "imageloader/Cache"); ImageLoaderConfigurationconfig = new ImageLoaderConfiguration .Builder(this) .memoryCacheExtraOptions(480, 800) // maxwidth, max height,即保存的每個緩存文件的最大長寬 .threadPoolSize(3)//線程池內加載的數量 .threadPRiority(Thread.NORM_PRIORITY -2) .denyCacheImageMultipleSizesInMemory() .memoryCache(new UsingFreqLimitedMemoryCache(2* 1024 * 1024)) // You can pass your own memory cache implementation/你可以通過自己的內存緩存實現 .memoryCacheSize(2 * 1024 * 1024) .discCacheSize(50 * 1024 * 1024) .discCacheFileNameGenerator(newmd5FileNameGenerator())//將保存的時候的URI名稱用MD5 加密 .tasksProcessingOrder(QueueProcessingType.LIFO) .discCacheFileCount(100) //緩存的文件數量 .discCache(new UnlimitedDiscCache(cacheDir))//自定義緩存路徑 .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) .imageDownloader(new BaseImageDownloader(this,5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超時時間 .writeDebugLogs() // Remove for releaseapp .build();//開始構建 ImageLoader.getInstance().init(config);

3、創建ImageLoader

ImageLoader imageLoader imageLoader = ImageLoader.getInstance();

4、緩存及圖像設置

DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.ic_stub) //加載圖片時的圖片 .showImageForEmptyUri(R.drawable.ic_empty) //沒有圖片資源時的默認圖片 .showImageOnFail(R.drawable.ic_error) //加載失敗時的圖片 .cacheInMemory(true) //啟用內存緩存 .cacheOnDisk(true) //啟用外存緩存 .considerExifParams(true) //啟用EXIF和JPEG圖像格式 .displayer(new RoundedBitmapDisplayer(20)) //設置顯示風格這里是圓角矩形 .build();

5.1、監聽

imageLoader.loadImage(imageUrl, options, new ImageLoadingListener() { @Override public void onLoadingStarted(String s, View view) { } @Override public void onLoadingFailed(String s, View view, FailReason failReason) { } @Override public void onLoadingComplete(String s, View view, Bitmap bitmap) { } @Override public void onLoadingCancelled(String s, View view) { } });

5.2、添加圖片

imageLoader.displayImage(imageUrl, imageview, options, animateFirstListener);

6、清理緩存:

imageLoader.clearMemoryCache(); imageLoader.clearDiskCache();
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 柞水县| 弋阳县| 潢川县| 沙湾县| 政和县| 斗六市| 丽江市| 仙桃市| 突泉县| 定西市| 峨眉山市| 海伦市| 汨罗市| 库车县| 宁德市| 乌海市| 务川| 开原市| 三原县| 双鸭山市| 枞阳县| 阿坝县| 伊金霍洛旗| 南乐县| 图木舒克市| 临沧市| 辉县市| 潢川县| 大丰市| 塔河县| 特克斯县| 陵水| 婺源县| 巴楚县| 兰西县| 沁阳市| 徐汇区| 瑞昌市| 沅陵县| 龙口市| 六安市|