首先先上官網(wǎng)地址:
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!
我們經(jīng)常需要再安卓程序中加載圖片些侍,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.
修改圖片以便適應(yīng)布局和減少內(nèi)存大小
Picasso.with(context).load(url).resize(50,50).centerCrop().into(imageView)
Picasso supports both download and error placeholders as optional features.
Picasso同時(shí)支持下載和加載錯(cuò)誤占位圖的可選功能
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資源或者手機(jī)本地圖片資源
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); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
有幾種引用這個(gè)庫(kù)的方式篡腌,一種是下載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,自己動(dòng)手豐衣足食
在Module下的build.gradle下加入
compile'com.squareup.picasso:picasso:2.5.2'
然后在layout中添加幾個(gè)ImageView
然后在代碼中
Picasso.with(this).load(API.IMAGE_URI).into(ivPicasso);//不支持加載gif
Picasso.with(this).load(API.IMAGE_URI).resize(200,200).into(ivPicassoResize);
看看效果吧,啦啦啦