【问题标题】:Set Picasso image as ListView Background将毕加索图像设置为 ListView 背景
【发布时间】:2014-08-21 04:57:07
【问题描述】:

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

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

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

任何帮助将不胜感激。

谢谢。 :D

【问题讨论】:

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


    【解决方案1】:

    您可以尝试覆盖 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 中不起作用。

    【讨论】:

    • 我一定会试试这个并回复你。谢谢:D
    • 如果您这样做,Target 将被垃圾回收。直接在视图持有者或View子类上实现接口。
    • 感谢您指出这一点,我也在研究那个界面。
    【解决方案2】:

    实现Target 类。

    伪代码:

    Picasso.with(context).load(...).into(
        new Target() {
    
        public void onLoaded(Bitmap bitmap, Picasso.LoadedFrom from){
            mListView.setBackground(bitmap);
        }
    
        /* ... */
    
        }
    );
    

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

    【讨论】:

    • 我一定会试试这个并回复你。谢谢:D
    • 如果您这样做,Target 将被垃圾回收。直接在视图持有者或View子类上实现接口。
    猜你喜欢
    • 2015-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 2015-01-24
    • 2015-12-12
    相关资源
    最近更新 更多