- 使用GlideBuilder的实现类来指定Glide缓存
public class GlideCache implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
//设置图片的显示格式ARGB_8888(指图片大小为32bit)
builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
//设置缓存目录(都可以自定义的)
File storageDirectory = Environment.getExternalStorageDirectory();
String downloadDirectoryPath=storageDirectory+"/GlideCache";
//设置缓存的大小为100M
int cacheSize = 100*1000*1000;
builder.setDiskCache( new DiskLruCacheFactory(downloadDirectoryPath, cacheSize)
);
}
@Override
public void registerComponents(Context context, Glide glide)
{ }
}
- 在AndroidManifest中配置GlideCache,
<meta-data android:name="包名.GlideCache"
android:value="GlideModule"/>