Picasso - 下载图像一次然后加载到多个ImageView

时间:2016-10-02 14:13:40

标签: android picasso

是否有人知道如何下载图片,然后使用相同的Picasso实例加载到多个ImageView?现在我正在使用如下所示的(非常糟糕的)解决方法,以确保图像已经缓存而不是再次下载。

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() {

    }
});

1 个答案:

答案 0 :(得分:0)

你可以这样做:

    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() {

          }
        });

要使用centerCrop(),只需添加:

imageView2.setScaleType(ImageView.ScaleType.CENTER_CROP);