1、导包ImageLoader
2、创建默认的ImageLoader配置参数
DisplayImageOptions options = new DisplayImageOptions.Builder() // 设置图片下载期间显示的图�?
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
.cacheInMemory(true) // 设置下载的图片是否缓存在内存�?
.cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中
.resetViewBeforeLoading(true)
// .displayer(new RoundedBitmapDisplayer(20)) // 设置成圆角图�?
.build(); // 创建配置过得DisplayImageOption对象
//创建默认的ImageLoader配置参数
ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(getApplicationContext())
.memoryCacheExtraOptions(480, 800)
.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(new Md5FileNameGenerator())//将保存的时候的URI名称用MD5 加密
.tasksProcessingOrder(QueueProcessingType.LIFO)
.discCacheFileCount(100) //缓存的文件数量
.defaultDisplayImageOptions(options)
.imageDownloader(new BaseImageDownloader(getApplicationContext(), 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
.writeDebugLogs() // Remove for release app
.build();//开始构建
//Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(configuration);
3、直接displayImage(图片ID,要显示布局的ID)
private DisplayImageOptions options;
//构造函数中
options = new DisplayImageOptions.Builder().showStubImage(R.drawable.logo) // 设置图片下载期间显示的图
.showImageOnLoading(R.drawable.logo)
.showImageForEmptyUri(R.drawable.sosuo) // 设置图片Uri为空或是错误的时候显示的图片
.showImageOnFail(R.drawable.logo) // 设置图片加载或解码过程中发生错误显示的图
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
.cacheInMemory(true) // 设置下载的图片是否缓存在内存
.cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中
.resetViewBeforeLoading(true)
.displayer(new RoundedBitmapDisplayer(20)) // 设置成圆角图
.build(); // 创建配置过得DisplayImageOption对象
imageView = (ImageView) this.findViewById(R.id.imageView);
//参数(图片链接地址,显示的id)
ImageLoader.getInstance().displayImage(url, imageView,options);
4、就是这么简单
如需代码,点击这里