图片三级缓存java
一级:内存Cachegit
二级:磁盘Cachegithub
存储目录:/packageName/cache/目录下
缓存
三级:网络网络
使用方法:app
一、在应用Application类中配置ui
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 config = new ImageLoaderConfiguration.Builder(context) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .tasksProcessingOrder(QueueProcessingType.LIFO) .writeDebugLogs() // Remove for release app .diskCacheFileCount(6) .build(); // Initialize ImageLoader with configuration. com.nostra13.universalimageloader.core.ImageLoader.getInstance().init(config); }
二、使用 this
默认才2倍采样率,能够更改。
spa
options = new DisplayImageOptions.Builder() .showStubImage(R.drawable.ic_launcher) .showImageForEmptyUri(R.drawable.ic_about_logo) .showImageOnFail(R.drawable.ic_arrow_back) .cacheInMemory(true) .cacheOnDisc(true) .bitmapConfig(Bitmap.Config.RGB_565) // 设置图片的解码类型 .build();
// 将图片显示任务增长到执行池,图片将被显示到ImageView当轮到此ImageView ImageLoader.getInstance() .displayImage(mAppInfos.get(position).getIconSourceUrl(), holder.iv, options);
github地址:https://github.com/nostra13/Android-Universal-Image-Loadercode