How To Use universal image loader offline caching?

前端 未结 5 1126
南方客
南方客 2020-12-05 08:37

Is it possible to catch offline using universal image loader? If possible, how to use it? Using configs? How To Set Download Directory manually?

out of memory erroro

5条回答
  •  广开言路
    2020-12-05 08:40

    You can use the ImageLoaderConfiguration.Builder class to customize disk caching. This includes the methods:

    • diskCacheExtraOptions()
    • diskCacheSize() (in bytes).
    • diskCacheFileCount()
    • diskCacheFileNameGenerator()
    • and some others.

    Or you can just use diskCache(DiskCache) to provide a custom class for implementing offline caching.

    From the example in the Configuration section of the wiki:

    File cacheDir = StorageUtils.getCacheDirectory(context);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
        .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
        .diskCacheExtraOptions(480, 800, null)
        .taskExecutor(...)
        .taskExecutorForCachedImages(...)
        .threadPoolSize(3) // default
        .threadPriority(Thread.NORM_PRIORITY - 1) // default
        .tasksProcessingOrder(QueueProcessingType.FIFO) // default
        .denyCacheImageMultipleSizesInMemory()
        .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
        .memoryCacheSize(2 * 1024 * 1024)
        .memoryCacheSizePercentage(13) // default
        .diskCache(new UnlimitedDiscCache(cacheDir)) // default
        .diskCacheSize(50 * 1024 * 1024)
        .diskCacheFileCount(100)
        .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
        .imageDownloader(new BaseImageDownloader(context)) // default
        .imageDecoder(new BaseImageDecoder()) // default
        .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
        .writeDebugLogs()
        .build();
    

提交回复
热议问题