1.添加依賴: compile files('libs/image-loader.jar')web
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);//加載圖片