[英]Picasso - Download image once then load into multiple ImageView
Does anyone know how to download an image once then use the same Picasso
instance to load into multiple ImageView
? 有谁知道如何一次下载图像然后使用相同的
Picasso
实例加载到多个ImageView
? Right now I'm using a (pretty bad) workaround like the one below, in order to be sure the image is already cached and not downloaded again. 现在,我正在使用一种(非常糟糕的)替代方法,如下所示,以确保该图像已被缓存并且不会再次下载。
Picasso.with(container.getContext()).load(photo.getPath()).placeholder(R.drawable.placeholder_outfit).fit().centerCrop().into(image1, new Callback() {
@Override
public void onSuccess() {
Picasso.with(container.getContext()).load(photo.getPath()).placeholder(R.drawable.placeholder_outfit).fit().centerCrop().into(image2);
}
@Override
public void onError() {
}
});
You can do it like this: 您可以这样做:
Picasso.with(container.getContext())
.load(photo.getPath())
.placeholder(R.drawable.placeholder_outfit)
.fit()
.centerCrop().into(image1, new Callback() {
@Override
public void onSuccess() {
imageView2.setImageDrawable(image1.getDrawable()); //Get the ImageView's image (this won't download it, it will get the downloaded image) and set it to your second imageView.
}
@Override
public void onError() {
}
});
To use centerCrop()
, just add: 要使用
centerCrop()
,只需添加:
imageView2.setScaleType(ImageView.ScaleType.CENTER_CROP);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.