我使用Glide在我的Android应用程序中加载图像.
3.5更新后,开发人员提供了GlideModule接口.
根据这篇文章(Disk Cache)我可以设置缓存目录,使用setDiskCache
方法和ExternalCacheDiskCacheFactory
.
但我没有看到任何区别.所有缓存仍在默认缓存目录中的内部存储上.
build.gradle:
dependencies { ... compile 'com.github.bumptech.glide:glide:3.6.1' }
Android清单:
GlideConfig.java:
public class GlideConfig implements GlideModule { @Override public void applyOptions(Context context, GlideBuilder builder) { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { Log.e("GlideConfig", "MEDIA_MOUNTED"); builder.setDiskCache( context.getString(R.string.app_name), 419430400));//400Mb //Environment.getExternalStorageDirectory().getPath() // + "/" // + context.getString(R.string.app_name) } else { Log.e("GlideConfig", "!MEDIA_MOUNTED"); } } @Override public void registerComponents(Context context, Glide glide) { } }
proguard-rules.pro:
... -keepnames class * com.myapp.GlideConfig
滑行使用:
Glide.with(context) .load("some_url") .dontAnimate() .centerCrop() .override(100, 100) .into(holder.iv_image);
pRaNaY.. 11
GlideBuilder
使用值设置setDiskCache
您可以将ExternalStorageDirectory设置为缓存目录.
if (!Glide.isSetup()) { GlideBuilder gb = new GlideBuilder(this); DiskCache dlw = DiskLruCacheWrapper.get(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/YourCacheDirectory/"), 250 * 1024 * 1024); gb.setDiskCache(dlw); Glide.setup(gb); }
检查无法设置GlideBuilder
希望对你有所帮助.
GlideBuilder
使用值设置setDiskCache
您可以将ExternalStorageDirectory设置为缓存目录.
if (!Glide.isSetup()) { GlideBuilder gb = new GlideBuilder(this); DiskCache dlw = DiskLruCacheWrapper.get(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/YourCacheDirectory/"), 250 * 1024 * 1024); gb.setDiskCache(dlw); Glide.setup(gb); }
检查无法设置GlideBuilder
希望对你有所帮助.