Can't set GlideBuilder

我是研究僧i 提交于 2019-12-23 19:34:08

问题


I use Glide library for Android. I want to set the cache in my custom folder, so the standard cache folder can be clean (with Master Clean for example). For this reason I use this code from manual, but this don't work for me.

My code:

DiskCache.Factory diskCacheFactory = new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                DiskCache diskCache = DiskLruCacheWrapper.get(getFilesDir(), 1024*1024*100);
                return diskCache;
            }
        };
        new GlideBuilder(this).setDiskCache(diskCacheFactory);
        Glide.with(this)
                .load("http://www.website.com/1.jpg")
                .into(imageView);

After I run this app Glide saves the image in the default folder.


回答1:


Try use:

if (!Glide.isSetup()) {
   GlideBuilder gb = new GlideBuilder(this);
   DiskCache dlw = DiskLruCacheWrapper.get(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myCatch/"), 250 * 1024 * 1024);
   gb.setDiskCache(dlw);
   Glide.setup(gb);
}



回答2:


In Glide 3.5, Glide.isSetup() and Glide.setup() are deprecated. The best way to do this is to use GlideModules to do this kind of configuration lazily. Check out the wiki page on configuration.



来源:https://stackoverflow.com/questions/28540216/cant-set-glidebuilder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!