首先先上官网地址:
http://square.github.io/picasso/
Images add much-needed context and visual flair to Android applications. Picasso allows for hassle-free image loading in your application—often in one line of code!
我们经常需要再安卓程序中加载图片,Picasso为我们提供了只要一行代码就能加载图片的的方式
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Transform images to better fit into layouts and to reduce memory size.
修改图片以便适应布局和减少内存大小
Picasso.with(context).load(url).resize(50,50).centerCrop().into(imageView)
Picasso supports both download and error placeholders as optional features.
Picasso同时支持下载和加载错误占位图的可选功能
Picasso.with(context)
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(imageView);
Resources, assets, files, content providers are all supported as image sources.
支持其他形式的图片资源加载,如drawable资源,assets资源或者手机本地图片资源
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1); Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2); Picasso.with(context).load(newFile(...)).into(imageView3);
有几种引用这个库的方式,一种是下载jar包
http://repo1.maven.org/maven2/com/squareup/picasso/picasso/2.5.2/picasso-2.5.2.jar
还有是MAVEN
另外一种是Gradle
compile'com.squareup.picasso:picasso:2.5.2'
OK,自己动手丰衣足食
在Module下的build.gradle下加入
compile'com.squareup.picasso:picasso:2.5.2'
然后在layout中添加几个ImageView
然后在代码中
Picasso.with(this).load(API.IMAGE_URI).into(ivPicasso);//不支持加载gif
Picasso.with(this).load(API.IMAGE_URI).resize(200,200).into(ivPicassoResize);
看看效果吧,啦啦啦