如何执行以下任务
使用图像缓存框架和网络框架吗?
在我的实现下方
Picasso.get().load(introduction.getImage()).into(holder.imageView);
我找到了这个样本:
Picasso.with(context)
.load(Uri.parse(getItem(position).getStoryBigThumbUrl()))
.networkPolicy(NetworkPolicy.OFFLINE)
.into(holder.storyBigThumb, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
// Try again online if cache failed
Picasso.with(context)
.load(Uri.parse(getItem(position)
.getStoryBigThumbUrl()))
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(holder.storyBigThumb);
}
});
答案 0 :(得分:0)
您可以将
NetworkPolicy.OFFLINE
与Picasso
一起使用。
if (introduction.getImage() != null) {
Picasso.get().load(introduction.getImage()).resize(100, 100).centerCrop().
networkPolicy(NetworkPolicy.OFFLINE).into(holder.imageView, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
Picasso.get().load(R.drawable.ic_contact).resize(100, 100).centerCrop().
into(holder.imageView);
}
});
}