public class MApp extends Application {
//配置imageloader緩存目錄緩存到img目錄下;自定義緩存目錄******
File cacheFile = new File(Environment.getExternalStorageDirectory() + "/" + "img");
@Override
public void onCreate() {
super.onCreate();
//初始化元件,鍊式開發思想,整個架構的參數初始化配置
//imageLoader的全局架構配置
ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this)
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions 記憶體緩存檔案的最大長寬
.diskCacheExtraOptions(480, 800, null) // 本地緩存的詳細資訊(緩存的最大長寬),最好不要設定這個
.threadPoolSize(3) //配置線程池的數量 ******
.threadPriority(Thread. NORM_PRIORITY) //預設線程優先級 10表示最高優先級,5是普通優先級,1表示最低優先級,
.tasksProcessingOrder(QueueProcessingType.FIFO) // default
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new LruMemoryCache(2 * 1024 * 1024)) //可以通過自己的記憶體緩存實作
.memoryCacheSize(2 * 1024 * 1024) // 記憶體緩存的最大值
.memoryCacheSizePercentage(13) // default
.diskCacheSize(50 * 1024 * 1024) // 50 Mb sd卡(本地)緩存的最大值****
.diskCacheFileCount(100) // 可以緩存的檔案數量
.diskCache(new UnlimitedDiskCache(cacheFile))//自定義緩存目錄*******
// default為使用HASHCODE對UIL進行加密命名, 還可以用MD5(new Md5FileNameGenerator())加密
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
.writeDebugLogs() // 列印debug log
.build();
//初始化;
ImageLoader.getInstance().init(configuration);
}
}
//圖檔一些必要的設定
public class ImageLoaderUtils_circle {
public static DisplayImageOptions getDisplayImageOption() {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnFail(R.mipmap.ic_launcher) //配置預設圖******
.showImageOnLoading(R.mipmap.ic_launcher)//配置預設圖******
.showImageForEmptyUri(R.mipmap.ic_launcher)//配置預設圖******
.bitmapConfig(Bitmap.Config.ARGB_8888)//配置圖檔解碼格式,圖檔比較清晰 *****
.cacheInMemory(true) //是否緩存到記憶體 ******
.cacheOnDisk(true) //是否緩存到sd卡 ******
.displayer(new RoundedBitmapDisplayer(20))//*******是否設定為圓角,弧度為多少
.build();
return options;
}
public static DisplayImageOptions getDisplayImageOption2() {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnFail(R.mipmap.ic_launcher) //配置預設圖******
.showImageOnLoading(R.mipmap.ic_launcher)//配置預設圖******
.showImageForEmptyUri(R.mipmap.ic_launcher)//配置預設圖******
.bitmapConfig(Bitmap.Config.ARGB_8888)//配置圖檔解碼格式,圖檔比較清晰 *****
.cacheInMemory(true) //是否緩存到記憶體 ******
.cacheOnDisk(false) //是否緩存到sd卡 ******
.displayer(new RoundedBitmapDisplayer(20))//*******是否設定為圓角,弧度為多少
.build();
return options;
}
}