我有Picasso的图像加载实现。我希望它在从URL加载图像时显示进度条。加载时,进度条将被隐藏。如果它不能,我希望它显示错误图像,甚至然后隐藏ProgressBar。
但如果没有网络连接,它永远不会调用onError,并且ProgressBar始终可见。
public class PicassoShowImageHideProgressBarCallback extends Callback.EmptyCallback {
private ImageView mImageView;
private ProgressBar mProgressBar;
private static final String TAG = "PicassoShowImageHidePro";
public PicassoShowImageHideProgressBarCallback(ImageView imageView,
ProgressBar progressBar) {
mImageView = imageView;
mProgressBar = progressBar;
}
@Override
public void onSuccess() {
mImageView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
@Override
public void onError() {
mProgressBar.setVisibility(View.GONE);
}
}
@BindView(R.id.poster_image)
ImageView mImageView;
@BindView(R.id.pb_progress_loading)
ProgressBar mProgressBar;
Picasso.with(mContext).load(path).error(R.drawable.ic_error).into(mImageView,
new PicassoShowImageHideProgressBarCallback(mImageView, mProgressBar));
答案 0 :(得分:0)