picasso图片下载缓存库使用

picasso是Square公司开源的一个Android图形缓存库,地址http://square.github.io/picasso/,可以实现图片下载和缓存功能。github地址https://github.com/square/picasso

下载

在build.gradle文件添加

compile 'com.squareup.picasso:picasso:2.5.2'

使用

初始化

方法一(推荐,并自己进行封装)

Picasso picasso=Picasso.with(context);    
picasso.load(url);

方法二

Picasso..with(context).load(url);

参数详解

 //此方法适用于不设置大小,自动进行适配
 Picasso.with(context) //             
.load(url)// 加载的URL
.placeholder(R.mipmap.ic_launcher) //loading期间显示的图片
.error(R.mipmap.ic_launcher) //加载失败显示的图片
.fit() //适配
.tag(context) //
.into(holder.imageView);//需要显示加载图片的ImageView
 //此方法适用于设置图片大小,不进行适配
Picasso.with(context)            
.load(url)
.placeholder(R.mipmap.ic_launcher)
.error(R.mipmap.ic_launcher)
.resizeDimen(R.dimen.img_width, R.dimen.img_width)//此处给的是一个资源dimen的id,
.centerInside()
.tag(context)
.into(holder.imageView);

有兴趣可以看看,图片下载缓存库picasso解析

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值