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;
}
}