ImagerLoader 的使用和配置 以及存储

来源:互联网 发布:java实现三级联动 编辑:程序博客网 时间:2024/05/22 13:54

public class MApp extends Application{
File cacheFile= new File(Environment.getExternalStorageDirectory()+”/”+”imgages”);

@Overridepublic void onCreate() {    super.onCreate();    //初始化组件,链式开发思想,整个框架的参数初始化配置    ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this)            .memoryCacheExtraOptions(480, 800) // default = device screen dimensions 内存缓存文件的最大长宽            .diskCacheExtraOptions(480, 800, null)  // 本地缓存的详细信息(缓存的最大长宽),最好不要设置这个            .tasksProcessingOrder(QueueProcessingType.FIFO) // default            .denyCacheImageMultipleSizesInMemory()            .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) //可以通过自己的内存缓存实现            .memoryCacheSize(2 * 1024 * 1024)  // 内存缓存的最大值            .memoryCacheSizePercentage(13) // default            .threadPoolSize(10)//线程池            .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()            .showImageOnLoading(R.mipmap.ic_launcher) //设置图片在下载期间显示的图片            .showImageForEmptyUri(R.mipmap.ic_launcher)//设置图片Uri为空或是错误的时候显示的图片            .showImageOnFail(R.mipmap.ic_launcher)  //设置图片加载/解码过程中错误时候显示的图片            .cacheInMemory(true)//设置下载的图片是否缓存在内存中            .cacheOnDisk(true)            .considerExifParams(true)  //是否考虑JPEG图像EXIF参数(旋转,翻转)            .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)//设置图片以如何的编码方式显示            .bitmapConfig(Bitmap.Config.RGB_565)//设置图片的解码类型//            .displayer(new RoundedBitmapDisplayer(5))//是否设置为圆角,弧度为多少

// .displayer(new FadeInBitmapDisplayer(100))//是否图片加载好后渐入的动画时间
.build();//构建完成
return options;
}
}