ImageLoader三級快取和清除快取
阿新 • • 發佈:2019-02-19
public class ImageLoaderPicture {
private DisplayImageOptions options;
public ImageLoaderPicture(Context context) {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.memoryCache(new WeakMemoryCache())
.build();
ImageLoader.getInstance().init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(0)
.showImageForEmptyUri(0)
.showImageOnFail(0)
.cacheOnDisk(true)
.cacheInMemory(true)
.cacheInMemory().cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(android.graphics.Bitmap.Config.RGB_565)
.build();
}
public DisplayImageOptions getOptions() {
return options;
}
public void setOptions(DisplayImageOptions options) {
this.options = options;
}
private DisplayImageOptions options;
public ImageLoaderPicture(Context context) {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.memoryCache(new WeakMemoryCache())
.build();
ImageLoader.getInstance().init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(0)
.showImageForEmptyUri(0)
.showImageOnFail(0)
.cacheOnDisk(true)
.cacheInMemory(true)
.cacheInMemory().cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(android.graphics.Bitmap.Config.RGB_565)
.build();
}
public DisplayImageOptions getOptions() {
return options;
}
public void setOptions(DisplayImageOptions options) {
this.options = options;
}
}
ImageLoader.getInstance().clearMemoryCache();清除記憶體
ImageLoader.getInstance().clearDiskCache();清除sd卡
ImageLoaderConfiguration
//硬碟快取10MB
.diskCacheSize(10 * 1024 * 1024)
//記憶體快取2M
.memoryCacheSize(2 * 1024 * 1024)