ImageLoader 缓存图片 并配置全局

//适配器中的代码

 //配置色彩模式为RGB_4444
        DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .bitmapConfig(Bitmap.Config.ARGB_4444)
                .build();
        ImageLoader.getInstance().displayImage(list.get(i).getImageUrl(),hodler.imageView,displayImageOptions);

//MyApp中的代码 ( 注意继承的是Application )

public class MyApp extends Application{
    //ImageLoader来加载图片,并全局配置,配置本地缓存路径在SDCard下imagefile目录
    @Override
    public void onCreate() {
        super.onCreate();
        File file = new File(Environment.getExternalStorageDirectory(),"imagefile");
        ImageLoaderConfiguration imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this)
                .diskCache(new UnlimitedDiskCache(file))
                .build();
      ImageLoader.getInstance().init(imageLoaderConfiguration);
    }
}

最后不要忘记在清单文件中添加name 还有网络请求权限哦!

猜你喜欢

转载自blog.csdn.net/qq_42809182/article/details/83374512