android三级缓存

public class MyApp extends Application {
    private static final String TAG = "---MyApp";
    private Context context;getOptions

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        Log.d(TAG, "应用创建---");
        initImageLoader();
    }

    private void initImageLoader() {
        //Configuration 配置
        //Builder 建造者模式
        //存到images
        String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/images";
        File file = new File(sdcardPath);
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                //内存配置
                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
                //磁盘缓存
//                .diskCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG, 75, null)
                .threadPoolSize(3) // 线程池里面线程的数量
                .threadPriority(Thread.NORM_PRIORITY - 1) // 线程优先级
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))//内存缓存的大小
                .memoryCacheSize(2 * 1024 * 1024)
                .diskCache(new UnlimitedDiskCache(file)) // 指sdcard的缓存路径
                .diskCacheSize(50 * 1024 * 1024)//指sdcard的缓存大小
//                .diskCacheFileCount(100)//指sdcard的缓存文件数量
                .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(context)) // default
//                .imageDecoder(new BaseImageDecoder()) // 图片解码
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .writeDebugLogs()
                .build();
        //记得配置到ImageLoader
        ImageLoader.getInstance().init(config);
    }
    //加载图片时候的配置
    public static DisplayImageOptions getOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.ic_launcher) // 加载过程中显示的图片
                .showImageForEmptyUri(R.mipmap.ic_launcher) //当地址为空的时候显示的图片
                .showImageOnFail(R.mipmap.ic_launcher) // 加载错误时显示的图片
                .resetViewBeforeLoading(true)  // 加载前重置视图
                .cacheInMemory(true) // 启动内存缓存
                .cacheOnDisk(true) // 启动磁盘缓存
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
                .bitmapConfig(Bitmap.Config.ARGB_8888) // default
                .displayer(new SimpleBitmapDisplayer()) // default
                .displayer(new FadeInBitmapDisplayer(100))
                .handler(new Handler()) // default
                .build();
        return options;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦想不上班

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值