1.添加依赖: compile files('libs/image-loader.jar')
2.清单文件中注册初始化
初始化public static void initImageLoader(Context context) {
// 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.
ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
config.threadPriority(Thread.NORM_PRIORITY - 2);
config.denyCacheImageMultipleSizesInMemory();
config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
config.tasksProcessingOrder(QueueProcessingType.LIFO);
config.writeDebugLogs(); // Remove for release app
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config.build());
}
initImageLoader(this);//onCreate()方法中调用
3.加载图片
1)适配器中的使用
ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance
imageLoader.displayImage(data.get(position).getImgsrc(),holder.hIcon);
2)Activity中使用
ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance
imageLoader.displayImage("https://p.ssl.qhimg.com/dmsmty/114_114_90/t0179d5643da48ef32c.webp",image);//加载图片