如何使用Picasso显示ProgressBar

时间:2015-10-01 13:13:33

标签: android picasso

我有图片链接,我使用Picasso下载并显示它。我可以显示ProgressBar以显示图片正在加载吗?

这是我的代码:

Picasso.with(mContext)
         .load(MYurl.BASE_URL + "/" + getItem(position).getImgThumb())
         .into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
         finalViewHolder.asanaImg.setImageBitmap(bitmap);
}

@Override
public void onBitmapFailed(Drawable errorDrawable) {
}

@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});

1 个答案:

答案 0 :(得分:3)

在使用Picasso加载图像之前,必须先启动进度条。稍后你可以在加载或失败的回调中将其解除。

//start progressbar here
Picasso.with(mContext)
         .load(MYurl.BASE_URL + "/" + getItem(position).getImgThumb())
         .into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
         finalViewHolder.asanaImg.setImageBitmap(bitmap);
         //stop progressbar here
}

@Override
public void onBitmapFailed(Drawable errorDrawable) {
        //stop progressbar here
}

@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});