<meta-data android:name="com.juzifenqi.app.utils.GlideConfiguration" android:value="GlideModule"/> <meta-data android:name="com.bumptech.glide.integration.okhttp3.OkHttpGlideModule" android:value="GlideModule"/>public class GlideConfiguration implements GlideModule { @Override public void applyOptions(Context context, GlideBuilder builder) { ViewTarget.setTagId(R.id.glide_tag_id); builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); // 设置磁盘缓存为100M,缓存在内部缓存目录 int cacheSize100MegaBytes = 104857600; builder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); // 20%大的内存缓存作为 Glide 的默认值 MemorySizeCalculator calculator = new MemorySizeCalculator(context); int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize); int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize); builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); } @Override public void registerComponents(Context context, Glide glide) { } }
<item name="glide_tag_id" type="id"/> values 下的ids.xml