Kei*_*ith 87 java android picasso
有没有办法在使用建筑师时听毕加索的事件,如:
Picasso.with(getContext()).load(url).into(imageView);
我想打电话requestLayout()和invalidate()父GridView所以它会适当调整,但我不知道如何设置监听器或回调.
我看到Picasso有错误事件报告,但有成功事件吗?
MrE*_*r13 258
您可以使用a Callback来获取onSuccess和onError事件.只需为您的请求添加一个新的回调,如下所示:
Picasso.with(getContext())
.load(url)
.into(imageView, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
}
});
Run Code Online (Sandbox Code Playgroud)
然后,您可以在onSuccess回调中执行任何更改和修改.
And*_*dme 30
如果您需要在将位图加载到视图之前访问该位图,请尝试使用:
private Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
}
@Override
public void onBitmapFailed() {
}
}
Run Code Online (Sandbox Code Playgroud)
在调用方法中:
Picasso.with(this).load("url").into(target);
Run Code Online (Sandbox Code Playgroud)
理想情况下,您可以直接在视图或视图持有者对象上实现Target.
希望这可以帮助
Square最近更新了Target类,现在有更多方法可以覆盖(onPrepareLoad和onBitmapFailed):
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)
你仍然需要使用:
Picasso.with(context).load(url).into(target);
Run Code Online (Sandbox Code Playgroud)
回答@Jas跟进问题作为对MrEngineer13的答案的评论(因为我没有足够的声誉在任何答案中发表评论),你应该error()在注册方法之前使用Callback该into()方法,例如:
Picasso.with(getContext())
.load(url)
.error(R.drawable.error_placeholder_image)
.into(imageView, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
//Success image already loaded into the view
}
@Override
public void onError() {
//Error placeholder image already loaded into the view, do further handling of this situation here
}
}
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
44516 次 |
| 最近记录: |