80,351
社区成员
发帖
与我相关
我的任务
分享
public static void initImageLoader(Context context) {
File cacheDir = StorageUtils.getOwnCacheDirectory(context, "imageloader/Cache");
ImageLoaderConfiguration configuration = new ImageLoaderConfiguration
.Builder(context)
.memoryCacheExtraOptions(480, 800) // max width, max height,即保存的每个缓存文件的最大长宽 // default = device screen dimensions
.threadPoolSize(3) //线程池内加载数量
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
//.memoryCache(new UsingFreqLimitedMemoryCache(14 * 1024 * 1024)) //You can pass your own memory cache implementation /你可以通过自己的内存缓存实现
.memoryCache(new WeakMemoryCache())
.memoryCacheSize(2 * 1024 * 1024)
.diskCacheSize(80 * 1024 * 1024)
.discCacheFileNameGenerator(new Md5FileNameGenerator()) //将保存的时候的URI名称用MD5 加密
.tasksProcessingOrder(QueueProcessingType.LIFO)
.discCacheFileCount(100) //缓存的文件数量
.diskCache(new UnlimitedDiskCache(cacheDir)) //自定义缓存路劲
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) //connectTimeout( 5s ), readTimeout ( 30 ) 超时时间
.writeDebugLogs() //Remove for release app
.build(); //开始构建
ImageLoader.getInstance().init(configuration);
}
public class DisplayImageOptionSetting {
public static DisplayImageOptions options;
public static DisplayImageOptions optionsCacheInDisc(){
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.video_default) //设置图片在下载期间显示的图片
.showImageForEmptyUri(R.drawable.image_background_empty) //设置图片Uri为空或是错误的时候显示的图片
.showImageOnFail(R.drawable.image_background_erro) //设置图片加载/解码过程中错误时候显示的图片
.cacheInMemory(false) //设置下载的图片是否缓存在内存中
.cacheOnDisk(true) //设置下载的图片是否缓存在SD卡中
.considerExifParams(true) //是否考虑JPEG图像EXIF参数(旋转,翻转)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT) //设置图片以如何的编码方式显示
.bitmapConfig(Bitmap.Config.RGB_565) //设置图片的解码类型//
//.decodingOptions(android.graphics.BitmapFactory.Options decodingOptions) //设置图片的解码配置
.delayBeforeLoading(0) //int delayInMillis为你设置的下载前的延迟时间
.resetViewBeforeLoading(true)//设置图片在下载前是否重置,复位
.displayer(new FadeInBitmapDisplayer(100))//是否图片加载好后渐入的动画时间
.build();//构建完成
return options;
}
}
public Holder setImageBuilderUIL(int viewId,String url,ImageLoader imageLoader,DisplayImageOptions options) {
ImageView view = getView(viewId);
imageLoader.displayImage(url,view,options);
return this;
}