MyApp ImageLoader配置+存储sd卡

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        //初始化ImageLoader
        //创建默认的ImageLoader配置参数
        String path = Environment.getExternalStorageDirectory().getPath();


        File dir = new File(path + "/images");
        //创建保存路径的文件夹
        if (!dir.exists()) {
            dir.mkdir();
        }


        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                .diskCache(new UnlimitedDiskCache(dir)) // default
                .build();
        ImageLoader.getInstance().init(config);
    }


    public static DisplayImageOptions getOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.ic_launcher) // resource or drawable
                .showImageForEmptyUri(R.mipmap.ic_launcher) // resource or drawable
                .showImageOnFail(R.mipmap.ic_launcher) // resource or drawable
                .cacheInMemory(true) // default
                .cacheOnDisk(true) // default
                .displayer(new SimpleBitmapDisplayer()) // default
                .handler(new Handler()) // default
                .build();
        return options;
    }

}


若只是实现图片的加载  -----------------------------------------------------------

public class App extends Application {


    @Override
    public void onCreate() {
        super.onCreate();


        initImageLoader();
    }


    /**
     * 初始化ImageLoader
     */
    private void initImageLoader() {
        ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(getApplicationContext()).build();
        ImageLoader.getInstance().init(configuration);
    }
}



猜你喜欢

转载自blog.csdn.net/liu_qunfeng/article/details/80726902
今日推荐