android - 将 Picasso 图像设置为 ListView 背景

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

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

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

但现在我想使用 id = myList 将此图像设置为我的 ListView 的背景。

如有任何帮助,我们将不胜感激。

谢谢。 :D

最佳答案

您可以尝试覆盖 new target() 实现来设置您的 View 。

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

关于android - 将 Picasso 图像设置为 ListView 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24496592/

相关文章:

java - SwipeRefreshLayout 与 Webview 不工作

java - RxJava - 单机无法运行

java - 从 AsyncTask 填充的 ListView 不会呈现

android - 如何更改特定 ListView 的项目或元素的颜色

Android ImageView扩展整个屏幕宽度

android - 如何查看安卓手机是否root?

php - MySQL 连接失败。无法连接到 'http' 上的 MySQL 服务器 (4)

android - 带有线性直线进度条的 ListView

android - setVisibility 在 android 中为 null

android - 使用前置摄像头捕捉图像