Picasso是Android中强大的图像下载和缓存库。
Picasso Introduction(介绍):
在Android应用程序中图片的添加有必须的环境和良好的视觉风格,Picasso可以很轻松的加载图片在你的应用程序中-通常在一行代码中。
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
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