【问题标题】:Picasso not always loading w/ ListViewPicasso 并不总是使用 ListView 加载
【发布时间】:2014-10-12 16:37:40
【问题描述】:

我使用的是 2.3.3,除了我的自定义 ListView 之外,一切似乎都运行良好。大多数时候,毕加索可以完美地加载我的图像,但在少数情况下图像永远不会加载并且微调器继续旋转。此外,有时加载微调器会显示在它后面加载的图像并设置了一些不透明度(目前还没有这个截图,但我会尝试抓取一个)。

这是我在 ArrayAdapter 中加载图像的方式:

Picasso picasso = new Picasso.Builder(getContext()).listener(
new Listener() {
        @Override
         public void onImageLoadFailed(Picasso arg0,
                                Uri arg1, Throwable arg2) {
                   if (Constants.debug) Log.i(LOG_TAG, "imageloadfailed");
                   arg2.printStackTrace();          
         }
        }).debugging(true).build(); 

picasso.load(imgUrl).placeholder(R.id.progress).into(h.picture, new Callback() {
        @Override
        public void onError() {
              if (Constants.debug) Log.i(LOG_TAG, "error");
        }

        @Override
        public void onSuccess() {
              if (Constants.debug) Log.i(LOG_TAG, "success");
        }
});

相关的 XML 部分:

    <!-- Image -->
    <RelativeLayout
    android:id="@+id/plist_image_container"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

        <ProgressBar                
            android:id="@+id/progress"
            android:layout_width="40dp"       
            android:layout_height="40dp"
            android:layout_centerInParent="true"/>

        <ImageView
           android:id="@+id/plist_item_thumb"
           android:adjustViewBounds="true"
           android:scaleType="fitCenter"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:gravity="center"/>           
   </RelativeLayout>

我永远不会进入 onImageLoadFailed(....),尽管在良好的网络上等待了相当长的时间,但图像永远不会加载。

这是我尝试加载的图像示例: http://res.cloudinary.com/spotlight-images/image/upload/v1408387652/IMG_1408387652509.jpg

编辑: 我最近从 AQuery 切换到 Picasso,AQuery 没有出现这个问题。

【问题讨论】:

  • 你解决了这个问题吗?如果你这样做,请发布答案
  • 我没有。我最终改用 Volley,一切正常。

标签: android picasso


【解决方案1】:

查看this link的答案

按照答案中的建议使用这些方法

onSuccess() {...}
onError() {...}

检查this link 是否有回调

【讨论】:

  • onError 永远不会被调用。即使图像不显示,onSuccess() 也会被调用。
  • 你能添加更多代码,以便我可以在我的机器上测试它
  • 代码库相当广泛,所以我不会全部发布。但是 Picasso 在自定义 ArrayAdapter 中被调用,如上所示。我将编辑 OP 以显示 XML 的相关部分。
【解决方案2】:
Picasso.with(getContext())
    .load(url)
    .into(imageView, new com.squareup.picasso.Callback() {
        @Override
        public void onSuccess() {

        }

        @Override
        public void onError() {

        }
    });

检查此代码可能会对您有所帮助...

【讨论】:

    猜你喜欢
    • 2017-08-15
    • 2018-08-27
    • 2012-08-10
    • 2013-06-25
    • 1970-01-01
    • 2018-09-27
    • 2016-11-19
    • 1970-01-01
    • 2017-01-14
    相关资源
    最近更新 更多