我试图将图像加载到我的视图中。有时它起作用,有时它不起作用。我正在API级别19模拟器上测试。新的Target内部的故障块永远不会被调用。我看到prepareLoad
,然后或者:加载毕加索的图像并不总是显示
onBitmapLoaded
被调用时,图像会显示- 图像不会显示
为什么会这样发生?
这发生在模拟器上。在物理设备上,Q & A报告了100%的故障率。在其他设备上,我看到间歇性故障率。这里发生了什么?
public void setBackground() {
final LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout);
final Context context = this;
final String imagePath = getStore().backgroundImageURI;
if (getStore().backgroundImageNumber > 0) {
mainLayout.setBackground(context.getResources().getDrawable(getStore().backgroundImageNumber));
return;
}
if (imagePath == null) {
mainLayout.setBackground(context.getResources().getDrawable(R.drawable.sk_collection_bg_default));
return;
}
Picasso.with(this).load(imagePath).into(new Target(){
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
Log.v("Biscuit-width", String.valueOf(bitmap.getWidth()));
Log.v("Biscuit-height", String.valueOf(bitmap.getHeight()));
mainLayout.setBackground(new BitmapDrawable(context.getResources(), bitmap));
}
@Override
public void onBitmapFailed(final Drawable errorDrawable)
{
Log.d("BISCUIT", "FAILED" + errorDrawable.toString());
}
@Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {
Log.d("TAG", "Prepare Load");
}
});
}
我没有看到任何异常记录 – quantumpotato