日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

android picasso源码下载,Picasso:一个专为Android制作的强大的图片下载和缓存库

發布時間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android picasso源码下载,Picasso:一个专为Android制作的强大的图片下载和缓存库 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Picasso:一個專為Android打造的強大的圖片下載和緩存庫

簡介

在Android應用中,圖片消費了大量的資源,卻為應用提供了很好的視覺體驗。幸運的是,Picasso為你的應用提供了非常容易的圖片加載方式——通常一行代碼就可以搞定!

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

Picasso處理了Android上圖片加載的許多坑:

1)在Adapter中,處理了ImageView的循環利用和取消下載。

2)耗費最小的內存處理了復雜的圖形變換。

3)在內存和磁盤中自動緩存圖片。

特點

Adapter中的下載

自動檢測adapter中的重用功能,且一旦發現重用,將自動取消之前的下載。

@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);

}

圖片轉換

變換圖片以便更好的適應布局,同時也減少了內存的使用。

Picasso.with(context)

.load(url)

.resize(50, 50)

.centerCrop()

.into(imageView)

你也可以自定義圖片的轉換方式以達到更復雜的變換要求。

public class CropSquareTransformation implements Transformation {

@Override public Bitmap transform(Bitmapsource) {

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 public String key() { return"square()"; }

}

將CropSquareTransformation這個類的一個實例傳遞給transform()函數即可。

占位圖片

Picasso同時支持“正在下載”時和“圖片下載出錯”后這兩種狀態展示的默認圖片。

Picasso.with(context)

.load(url)

.placeholder(R.drawable.user_placeholder)

.error(R.drawable.user_placeholder_error)

.into(imageView);

Picasso至多會嘗試三次下載,如果三次下載都失敗了,就會在原圖位置上展示“圖片下載出錯”時的圖片。

資源加載

Picasso支持將resources、assets、files和contentprovider作為圖片的加載源。

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);

調試指示器

開發者可以在圖片的左上角展示一個彩色的小三角,不同的顏色指明了圖片資源的不同來源。調用Picasso對象的setIndicatorsEnabled(true)方法就可以了。

下載

http://repo1.maven.org/maven2/com/squareup/picasso/picasso/2.5.2/picasso-2.5.2.jar

Picasso的源代碼,例子和這個網址(http://square.github.io/picasso/)都放在了GitHub上

MAVEN

com.squareup.picasso

picasso

2.5.2

GRADLE

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

為Picasso做貢獻

如果你想為Picasso開發貢獻你的代碼,你可以上github,然后fork該代碼庫,再把你的修改發給我們(pull request)。

在提交代碼的時候,請保持代碼的習慣和風格與原來的一致以便于盡可能保持代碼的可閱讀性。同時,為了保證你的代碼正確編譯,請運行mvn clean verify。

你需要同意Individual ContributorLicense Agreement (CLA)才能將你的代碼合并到Picasso工程中。

重要資料

1]Javadoc :

http://square.github.io/picasso/javadoc/index.html

[2]StackOverflow:http://stackoverflow.com/questions/tagged/picasso?sort=active

許可證

Copyright 2013 Square, Inc.

Licensed under the Apache License, Version2.0 (the "License");

you may not use this file except incompliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreedto in writing, software

distributed under the License isdistributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.

See the License for the specific languagegoverning permissions and

limitations under the License.

原文鏈接:http://square.github.io/picasso/

總結

以上是生活随笔為你收集整理的android picasso源码下载,Picasso:一个专为Android制作的强大的图片下载和缓存库的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。