Android------------ImageLoader加载图片

1.首先在Android studio的 libs包下导入universal- image-loader-1.9.5.jar, 然后右击该架包选择 Add as Libraly....  点击OK

2.在适配器内加入下列几行代码:

 //创建默认的ImageLoader配置参数
        ImageLoaderConfiguration configuration = ImageLoaderConfiguration
                .createDefault(context);

        //将configuration配置到imageloader中
        imageloader=ImageLoader.getInstance();
        imageloader.init(configuration);

        options=new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .bitmapConfig(Bitmap.Config.ARGB_8888)
                .showImageOnLoading(R.mipmap.ic_launcher)
                .showImageForEmptyUri(R.mipmap.ic_launcher)
                .showImageOnFail(R.mipmap.ic_launcher)
                .build();


3.加载图片最重要的一行:

imageloader.displayImage(news.getImgSrc(),vh.iv,options);

/*
DisplayImageOptions options = new DisplayImageOptions.Builder()
  .showImageOnLoading(R.drawable.ic_stub)            //加载图片时的图片
  .showImageForEmptyUri(R.drawable.ic_empty)         //没有图片资源时的默认图片
  .showImageOnFail(R.drawable.ic_error)              //加载失败时的图片
  .cacheInMemory(true)                               //启用内存缓存
  .cacheOnDisk(true)                                 //启用外存缓存
  .considerExifParams(true)                          //启用EXIF和JPEG图像格式
  .displayer(new RoundedBitmapDisplayer(20))         //设置显示风格这里是圆角矩形
  .build();
**/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值