ImageLoader加载图片 默认方式和自定义方式
2016-01-15 15:18
405 查看
public class MyApplication extends Application{
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
//默认的方式
//ImageLoaderConfiguration configuration=ImageLoaderConfiguration.createDefault(this);
//sdcard的路径
String sdPath=Environment.getExternalStorageDirectory().getPath();
//自定义的方式
ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(this)
.memoryCacheExtraOptions(480, 800)//内存缓存文件的最大长宽
.discCacheExtraOptions(480, 800, null)//本地缓存的详细信息
.threadPoolSize(3)//线程池内加载的数量
.threadPriority(Thread.NORM_PRIORITY-2)//设置当前线程的优先级
.tasksProcessingOrder(QueueProcessingType.FIFO)//设置任务的处理顺序
.denyCacheImageMultipleSizesInMemory()//防止内存中图片重复
.memoryCache(new LruMemoryCache(2*1024*1024))//设置自己的内存缓存大小 2M
.memoryCacheSize(2*1024*1024)
.memoryCacheSizePercentage(13)//内存缓存百分比
.discCache(new UnlimitedDiscCache(new File(sdPath+"/huang/image1")))//设置缓存的图片在sdcard中的位置
.discCacheSize(50*1024*1024)//硬盘缓存大小 50M
.discCacheFileCount(100)//硬盘缓存文件个数
.discCacheFileNameGenerator(new Md5FileNameGenerator())//md5加密的方式,或new HashCodeFileNameGenerator()
.imageDownloader(new BaseImageDownloader(this))
.imageDecoder(new BaseImageDecoder(true))//图片解码
.defaultDisplayImageOptions(getOption())//是否使用默认的图片加载配置,null表示不使用
.writeDebugLogs()
.build();
//初始化
ImageLoader.getInstance().init(configuration);
}
/*
* 设置option
*/
public static DisplayImageOptions getOption(){
DisplayImageOptions option=new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_launcher)//设置图片下载期间显示的图片
.showImageForEmptyUri(R.drawable.emptyurl)//设置图片uri为空或是错误的时候显示的图片
.showImageOnFail(R.drawable.emptyurl)//设置图片加载或解码过程中发生错误显示的图片
.resetViewBeforeLoading(false)//设置图片在加载前是否重置、复位
//.delayBeforeLoading(1000)//下载前的延迟时间
.cacheInMemory(true)//设置下载的图片是否缓存在内存中
.cacheOnDisk(true)//设置下载的图片是否缓存在sd卡中
.considerExifParams(false)//思考可交换的参数
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)//设置图片的显示比例
.bitmapConfig(Config.RGB_565)//设置图片的解码类型
.displayer(new RoundedBitmapDisplayer(40))//设置图片的圆角半径
.displayer(new FadeInBitmapDisplayer(3000))//设置图片显示的透明度过程的时间
.build();
return option;
}
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
//默认的方式
//ImageLoaderConfiguration configuration=ImageLoaderConfiguration.createDefault(this);
//sdcard的路径
String sdPath=Environment.getExternalStorageDirectory().getPath();
//自定义的方式
ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(this)
.memoryCacheExtraOptions(480, 800)//内存缓存文件的最大长宽
.discCacheExtraOptions(480, 800, null)//本地缓存的详细信息
.threadPoolSize(3)//线程池内加载的数量
.threadPriority(Thread.NORM_PRIORITY-2)//设置当前线程的优先级
.tasksProcessingOrder(QueueProcessingType.FIFO)//设置任务的处理顺序
.denyCacheImageMultipleSizesInMemory()//防止内存中图片重复
.memoryCache(new LruMemoryCache(2*1024*1024))//设置自己的内存缓存大小 2M
.memoryCacheSize(2*1024*1024)
.memoryCacheSizePercentage(13)//内存缓存百分比
.discCache(new UnlimitedDiscCache(new File(sdPath+"/huang/image1")))//设置缓存的图片在sdcard中的位置
.discCacheSize(50*1024*1024)//硬盘缓存大小 50M
.discCacheFileCount(100)//硬盘缓存文件个数
.discCacheFileNameGenerator(new Md5FileNameGenerator())//md5加密的方式,或new HashCodeFileNameGenerator()
.imageDownloader(new BaseImageDownloader(this))
.imageDecoder(new BaseImageDecoder(true))//图片解码
.defaultDisplayImageOptions(getOption())//是否使用默认的图片加载配置,null表示不使用
.writeDebugLogs()
.build();
//初始化
ImageLoader.getInstance().init(configuration);
}
/*
* 设置option
*/
public static DisplayImageOptions getOption(){
DisplayImageOptions option=new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_launcher)//设置图片下载期间显示的图片
.showImageForEmptyUri(R.drawable.emptyurl)//设置图片uri为空或是错误的时候显示的图片
.showImageOnFail(R.drawable.emptyurl)//设置图片加载或解码过程中发生错误显示的图片
.resetViewBeforeLoading(false)//设置图片在加载前是否重置、复位
//.delayBeforeLoading(1000)//下载前的延迟时间
.cacheInMemory(true)//设置下载的图片是否缓存在内存中
.cacheOnDisk(true)//设置下载的图片是否缓存在sd卡中
.considerExifParams(false)//思考可交换的参数
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)//设置图片的显示比例
.bitmapConfig(Config.RGB_565)//设置图片的解码类型
.displayer(new RoundedBitmapDisplayer(40))//设置图片的圆角半径
.displayer(new FadeInBitmapDisplayer(3000))//设置图片显示的透明度过程的时间
.build();
return option;
}
}
相关文章推荐
- leveldb代码阅读(14)——Level和Compaction
- OpenCV2:Mat属性type,depth,step
- jQuery 获取当前url各种信息
- Net User 命令
- Swift-06-闭包
- html5 中常用的标签和属性
- 欢迎使用CSDN-markdown编辑器
- 大数据认知阶段——如何学习大数据相关技术
- Ios开发Swift自定义UIbutton增加一个能设置高亮状态下背景颜色的方法
- 无法debug断点跟踪JDK源代码——missing line number attributes的解决方法
- IOS App发布问题:code signing is required for product type "Application" in SDK 'iOS 9.2'
- DataTable
- How to use Total Commander?
- CGImageSource Reference
- 存储过程与JAVA
- Cocos2dx个人笔记之屏幕适配
- Java输入输出流(1)
- Mutex 进程间互斥
- ansible安装测试
- Storm简介