将毕加索图像设置为ListView背景

时间:2014-06-30 18:28:30

标签: android android-listview android-imageview picasso android-background

我正在使用Picasso库将存储在我服务器上的图像加载到我的Android应用程序中。 我正在使用普通代码来执行此操作。

Picasso.with(context)
  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)

但现在我想将此图片设置为带有id = myList的列表视图的背景。

任何帮助将不胜感激。

谢谢。 :d

2 个答案:

答案 0 :(得分:3)

您可以尝试覆盖new target()实施以设置您的观点。

Picasso.with(context).load(url).into(new Target() {
        @Override public void onSuccess(Bitmap bitmap) {
          // Set imageview bitmap here.
          // Do other stuff.
        }

        @Override public void onError() {
        }
      });

请注意,除非您在Target中实现hashCode / equals,否则上述内容不会在ListView中工作。

答案 1 :(得分:2)

实施Target类。

伪代码:

Picasso.with(context).load(...).into(
    new Target() {

    public void onLoaded(Bitmap bitmap, Picasso.LoadedFrom from){
        mListView.setBackground(bitmap);
    }

    /* ... */

    }
);

请注意,此代码将无法编译,因为我不知道确切的API,但这会对您有所帮助。