ImageLoader配置&缓存

依赖

	implementation'com.nostra13.universalimageloader:universal-image-loader:1.9.5'	

在清单文件中找到
在这里插入图片描述

创建方法

	public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

    File file = StorageUtils.getCacheDirectory(this);

    ImageLoaderConfiguration build = new ImageLoaderConfiguration.Builder(this)
            .diskCache(new UnlimitedDiskCache(file))
            .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
            .build();

    ImageLoader.getInstance().init(build);

}
}

展示(适配器中使用)

 DisplayImageOptions build = new DisplayImageOptions.Builder()
            .showImageOnFail(R.mipmap.ic_launcher)
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .showImageForEmptyUri(R.drawable.ic_launcher_background)
            .build();

    ImageLoader.getInstance().displayImage(news.getPic_url(), handler.img, build);

猜你喜欢

转载自blog.csdn.net/weixin_44305652/article/details/86497587
今日推荐