【发布时间】:2019-12-24 10:18:54
【问题描述】:
我正在尝试检查 ImageView 是否加载了图像,并且该 URL 实际上具有图像资源。
ImageView dynamicImageView = new ImageView(context)
Picasso.get()
.load(myURL)
.resize(myWidth, myWidth)
.centerCrop()
.into(dynamicImageView, new Callback() {
@Override
public void onSuccess() {
Drawable drawable = dynamicImageView.getDrawable();
boolean hasImage = (drawable != null);
if (hasImage && (drawable instanceof BitmapDrawable)) {
hasImage = ((BitmapDrawable)drawable).getBitmap() != null;
}
}
@Override
public void onError(Exception e) {
}
});
这总是返回 true,因为 Picasso 会自动将默认的可绘制占位符填充到 dynamicImageView 中。
我应该怎么做才能在 URL 没有图像资源的情况下始终获得 “真实” 结果?
提前谢谢大家。
【问题讨论】:
-
您可以使用 Picasso API 的 Target 回调
标签: java android android-imageview picasso