Android Picasso的基本使用

Picasso是Android中强大的图像下载和缓存库。

Picasso Introduction(介绍):

在Android应用程序中图片的添加有必须的环境和良好的视觉风格,Picasso可以很轻松的加载图片在你的应用程序中-通常在一行代码中。

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);


在Android中图片加载大多数常见的陷阱是通过Picasso自动处理的。
1.处理图片回收和下载取消在Adapter中。
2.复杂的图像转换以最小的内存使用。
3.自动存储和磁盘缓存。

Picass Features(特点):

1.ADAPTER DOWNLOADS(适配器中加载):

适配器自动发现和重用以前的取消下载。
@Override public void getView(int position, View convertView, ViewGroup parent) {
  SquaredImageView view = (SquaredImageView) convertView;
  if (view == null) {
    view = new SquaredImageView(context);
  }
  String url = getItem(position);

  Picasso.with(context).load(url).into(view);
}

2.IMAGE TRANSFORMATIONS(图片转换):

转换图片以更好地适应到布局和减少内存的大小。
Picasso.with(context)
  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)

您还可以指定为更高级的效果自定义转换。
public class CropSquareTransformation implements Transformation {
  @Override public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    Bitmap result = Bitmap.createBitmap(source, x, y, size, size);
    if (result != source) {
      source.recycle();
    }
    return result;
  }

  @Override pu
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值