public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
//Fresco.initialize(this);
Fresco.initialize(this,ImagePipelineConfig.newBuilder(App.this)
.setMainDiskCacheConfig(
DiskCacheConfig.newBuilder(this)
//磁盤緩存路勁
.setBaseDirectoryPath(new File(Environment.getExternalStorageDirectory().getAbsolutePath()))
//設置一個緩存大小
.setMaxCacheSize(10*1024*1024)
.build()
)
.build()
);
}
//緩存大小
private static int MAX_MEM = 30 * ByteConstants.MB;
//設置 內存
@RequiresApi(api = Build.VERSION_CODES.N)
private ImagePipelineConfig getConfigureCaches(Context context) {
final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
MAX_MEM,// 內存緩存中總圖片的最大大小,以字節爲單位。
Integer.MAX_VALUE,// 內存緩存中圖片的最大數量。
MAX_MEM,// 內存緩存中準備清除但尚未被刪除的總圖片的最大大小,以字節爲單位。
Integer.MAX_VALUE,// 內存緩存中準備清除的總圖片的最大數量。
Integer.MAX_VALUE);// 內存緩存中單個圖片的最大大小。
Supplier<MemoryCacheParams> mSupplierMemoryCacheParams = new Supplier<MemoryCacheParams>() {
@Override
public MemoryCacheParams get() {
return bitmapCacheParams;
}
};
ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context);
builder.setBitmapMemoryCacheParamsSupplier((com.facebook.common.internal.Supplier<MemoryCacheParams>) mSupplierMemoryCacheParams);
return builder.build();
}
}
Fresco 的緩存
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.