毕加索不是onBitmapLoaded第一次打电话,如果你知道,请告诉我
txtView = (TextView) centerRelative.getChildAt(i);
Picasso.with(getBaseContext()).load(file[i-4]).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
txtView.setBackground(new BitmapDrawable(getResources(),bitmap));
// Not executing for the first time
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
// executing for the first time
}
});
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
txtView.setBackground(new BitmapDrawable(getResources(),bitmap));
logd("onBitmapLoaded");
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getBaseContext()).load(file[i-4]).into(target);
Run Code Online (Sandbox Code Playgroud)
解决方案:您必须在此处进行一些更改:
而不是写:
new Target() {...}
Run Code Online (Sandbox Code Playgroud)
在您的 中into(..),您必须创建一个Target类的全局对象。不要让它成为本地对象,因为它可能会被垃圾收集。所以,
第1步:
创建一个全局对象:
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
....
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
....
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
....
}
};
Run Code Online (Sandbox Code Playgroud)
最后,在您的into(...):
Picasso.with(getBaseContext()).load(file[i-4]).into(target);
Run Code Online (Sandbox Code Playgroud)
试试看,希望有帮助。
| 归档时间: |
|
| 查看次数: |
1065 次 |
| 最近记录: |