Android-Universal-Image-Loader的ImageLoaderConfiguration和DisplayImageOptions配置参数解析
2015-02-12 17:26
337 查看
在GitHub上面的一个开源类库(官方下载:https://github.com/nostra13/Android-Universal-Image-Loader)
Downloads
universal-image-loader-1.9.3.jaruniversal-image-loader-1.9.3-with-sources.jar (for
Eclipse)
// This configuration tuning is custom. You can tune every option, you may tune some of them, // or you can create default configuration by // ImageLoaderConfiguration.createDefault(this); // method. Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher); BitmapDrawable bd = new BitmapDrawable(this.getResources(),bitmap); DisplayImageOptions dio = new DisplayImageOptions.Builder().build(); DisplayImageOptions options = new DisplayImageOptions.Builder() /** * 传入另一个DisplayImageOptions会覆盖上面的设置 */ .cloneFrom(dio) /** * 加载时的图片 */ .showImageOnLoading(bd) .showImageOnLoading(R.drawable.ic_stub) .showStubImage(R.drawable.ic_stub) /** * 加载图片失败后显示的图片 */ .showImageOnFail(bd) .showImageOnFail(R.drawable.ic_error) /** * 加载图片为空的时候 */ .showImageForEmptyUri(bd) .showImageForEmptyUri(R.drawable.ic_empty) /** * 在内存中缓存 * 默认:true */ .cacheInMemory(true) .cacheInMemory() /** * 在磁盘中缓存 * 默认:true */ .cacheOnDisk(true) .cacheOnDisc(true) .cacheOnDisc() /** * 设置Bitmap.Config * 默认:Bitmap.Config.ARGB_8888 */ .bitmapConfig(Bitmap.Config.ARGB_8888) /** * 是否考虑EXIF的信息 * 默认:false */ .considerExifParams(false) /** * 设置解析图片参数 */ .decodingOptions(new Options()) /** * 设置加载图片的时间 * 默认:0 */ .delayBeforeLoading(0) /** * 设置自定义BitmapDisplayer * 默认:SimpleBitmapDisplayer */ .displayer(DefaultConfigurationFactory.createBitmapDisplayer()) /** * 设置辅助的传递对象 * 默认:null */ .extraForDownloader(null) /** * 设置自定义Hanlder */ .handler(null) /** * 设置解码时图片的缩放 * 默认:ImageScaleType.IN_SAMPLE_POWER_OF_2 */ .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) /** * 在图片加载到内存中前进行处理 * 默认:null */ .preProcessor(null) /** * 在显示图片时对图片处理 * 默认:null */ .postProcessor(null) /** * 设置是否在加载图片前重置 * 默认:true */ .resetViewBeforeLoading(true) .resetViewBeforeLoading() .build(); /** * universalimageloader配置 */ try { ImageLoaderConfiguration config; config = new ImageLoaderConfiguration.Builder(context) /** * 设置内存保存图片的最大高宽 * 默认:屏幕大小 */ .memoryCacheExtraOptions(480, 800) /** * 设置内存缓存,会优先用memoryCacheSize设置的值 * 默认:LruMemoryCache 1/8的应用缓存 */ .memoryCache(new LruMemoryCache(30)) /** * 设置最大的内存缓存(如果使用了memoryCache,就尽量不要使用此方法) * 默认:1/8的应用缓存 */ .memoryCacheSize(10) /** * 设置可用的内存缓存百分比(1-100)(如果使用了memoryCache,就尽量不要使用此方法) * 默认:1/8的应用缓存 */ .memoryCacheSizePercentage(12) /** * 设置磁盘缓存大小 * 默认:没有限制 */ .diskCacheSize(10) .discCacheSize(10) /** * 设置磁盘缓存文件的最大数量 * 默认:没有限制 */ .diskCacheFileCount(10) .discCacheFileCount(10) /** * 设置磁盘文件的命名方式 * 默认:HashCodeFileNameGenerator */ .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) /** * 设置磁盘缓存 * 默认:路径(/Android/data/[app_package_name]/cache),命名(HashCodeFileNameGenerator),大小(无限) * * tip:默认主路径是/Android/data/[app_package_name]/cache, * 但是如果sdcard处于挂起或无sdcard的情况时会使用/data/data/<application package>/cache * * */ .diskCache(new LruDiskCache(new File("/Android/data/[app_package_name]/cache"), new HashCodeFileNameGenerator(), 10)) .discCache(new LruDiskCache(new File("/Android/data/[app_package_name]/cache"), new HashCodeFileNameGenerator(), 10)) /** * 设置自定义Executor,用于加载本地无缓存的task * tip:threadPoolSize,threadPriority,tasksProcessingOrder将无效 */ .taskExecutor(null) /** * 设置自定义Executor,用于加载本地有缓存的task */ .taskExecutorForCachedImages(null) /** * 设置对队列的处理顺序 * 默认:QueueProcessingType.LIFO(FIFO, LIFO) */ .tasksProcessingOrder(QueueProcessingType.LIFO) /** * 设置线程的优先级(MIN_PRIORITY<threadPriority<MAX_PRIORITY) * 默认:Thread.NORM_PRIORITY - 2 */ .threadPriority(Thread.NORM_PRIORITY - 2) /** * 设置线程池的大小 * 默认:3 */ .threadPoolSize(3) /** * 设置图片的解码器 * 默认:BaseImageDecoder */ .imageDecoder(DefaultConfigurationFactory.createImageDecoder(true)) /** * 设置图片下载器 * 默认:BaseImageDownloader */ .imageDownloader(DefaultConfigurationFactory.createImageDownloader(this.getApplicationContext())) /** * 阻止同一个图片不同大小都存放在内存中(如果是同一个都在就去掉) * 默认:flase */ .denyCacheImageMultipleSizesInMemory() /** * 显示图片选项 * 默认:{ImageScaleType#IN_SAMPLE_POWER_OF_2} * {@link Bitmap.Config#ARGB_8888} * {@link SimpleBitmapDisplayer} */ .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) /** * 显示详细的log * 默认:false */ .writeDebugLogs() .build(); ImageLoader.getInstance().init(config); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Initialize ImageLoader with configuration.
相关文章推荐
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解 一、介绍
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Universal-Image-Loader解析(二)——DisplayImageOptions的详细配置与简单的图片加载
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Universal-Image-Loader解析(二)——DisplayImageOptions的详细配置
- Universal-Image-Loader解析(二)——DisplayImageOptions的详细配置
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Universal-Image-Loader解析(二)——DisplayImageOptions的详细配置与简单的图片加载
- Android Universal-Iamge-Loader的DisplayImageOptions
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Universal-Image-Loader解析(一)——ImageLoaderConfiguration的详细配置
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Android-Universal-Image-Loader ImageLoaderConfiguration 全局初始化此配置
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解