1

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

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

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

任何帮助,将不胜感激。

谢谢你。:D

4

2 回答 2

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 中不起作用。

于 2014-06-30T18:32:52.357 回答
2

实现Target类。

伪代码:

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

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

    /* ... */

    }
);

请注意,此代码不会编译,因为我不知道确切的 API,但这将进一步帮助您。

于 2014-06-30T18:31:56.860 回答