天天看點

picasso圖檔加載的優缺點Picasso

Picasso

picasso圖檔加載的使用

1、

核心方法

(1)、Picasso.with(context).load(“http://11111111111.png“).into(imageView);其中,context傳入上下文,load中寫入URI、URL位址,into中寫入ImageView控件,就是這麼簡單,任性。

(2)變換圖像可以更好地适應布局,并且減少記憶體大小。

Picasso.with(context)  
  .load(url)  
  .resize(, )  
  .centerCrop()  
  .into(imageView)  
           

resize中用于指定圖檔的大小,centerCrop用于指定從中間截取圖檔;

(3)錯誤加載圖檔顯示(會預設重複請求3次,然後才顯示錯誤加載圖檔)

Picasso.with(context)  
    .load(url)  
    .placeholder(R.drawable.user_placeholder)  
    .error(R.drawable.user_placeholder_error)  
    .into(imageView);  
           

(4)可以加載R資源,以及檔案等

Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);  

Picasso.with(context).load(new File(...)).into(imageView2);  
           

(5)開發時可以啟用彩帶來訓示圖像源。

在Picasso執行個體中調用setIndicatorsEnabled(true)。

在圖檔的左上角用顔色區分,

紅色:網絡擷取;

黃色:本地磁盤擷取;

綠色:從記憶體擷取;