1.配置AppGlideModule
通过继承 AppGlideModule 和添加 @GlideModule 注解来设置默认的结构
@GlideModule
public classMyGlideModuleextendsAppGlideModule {
/**
* 通过GlideBuilder设置默认的结构(Engine,BitmapPool ,ArrayPool,MemoryCache等等).
*
*@paramcontext
*@parambuilder
*/
@Override
public voidapplyOptions(Context context,GlideBuilder builder) {
String filePath = Environment.getExternalStorageDirectory().getPath() +"/Glide";
File file =newFile(filePath);
if(!file.exists()) {
file.mkdir();
}
//重新设置内存限制
builder.setMemoryCache(newLruResourceCache(10*1024*1024));
//设置缓存目录和大小
builder.setDiskCache(newDiskLruCacheFactory(filePath,100*1024*1024));
}
/**
* 为App注册一个自定义的String类型的BaseGlideUrlLoader
*
*@paramcontext
*@paramregistry
*/
@Override
public voidregisterComponents(Context context,Registry registry) {
super.registerComponents(context,registry);
}
@Override
public booleanisManifestParsingEnabled() {
return super.isManifestParsingEnabled();
}
}
2.获取 缓存的目录
String filePath = Environment.getExternalStorageDirectory().getPath() +"/Glide";
File file = GlideApp.getPhotoCacheDir(this,filePath);
网友评论