毕加索不加载图像 [英] Picasso not loading the image

查看:159
本文介绍了毕加索不加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的code毕加索:

here's the code for picasso:

ImageView img = (ImageView)findViewById(R.id.product_image);
    Picasso.with(this)
    .load(_url)
    .fit()
    .into(img, new Callback() {

        @Override
        public void onSuccess() {


        }

        @Override
        public void onError() {


        }
    });

这里的_url值:
    <一href=\"http://kiagallery.ir/Images/Upload/Collection%20101/Spring%20101/d4a03b66dc7b46c694615c549b78b2e9.jpg\" rel=\"nofollow\">http://kiagallery.ir/Images/Upload/Collection%20101/Spring%20101/d4a03b66dc7b46c694615c549b78b2e9.jpg

和这里的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView 
    android:id="@+id/product_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView 
    android:id="@+id/product_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="13sp"
    android:layout_below="@id/product_image"/>

<TextView
    android:id="@+id/product_price"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="13sp"
    android:layout_below="@id/product_name"/>
</RelativeLayout>

,你可以看到图像可以通过浏览器,但毕加索的访问无法加载它,我已经检查了onError的功能,它从来不叫,我在这里安静丢失,任何帮助将是AP preciated。

as you can see the image can be accessed via browser but picasso fails to load it, I've checked the onError function and it's never called, I'm quiet lost here, any help would be appreciated.

编辑:如果我给的ImageView宽度放大器;像200dp高度固定值,它加载图像,但是当我将其更改为WRAP_CONTENT它不显示图像。

When I give imageview's width & height fixed value like 200dp, it loads the image, but when I change it to wrap_content it doesn't show the image.

推荐答案

我的猜测是,你不应该调用飞度()方法毕加索,而你的ImageView有其宽度和高度由WRAP_CONTENT定义。这种方法等到ImageView的已测并调整图像的尺寸完全匹配。当你的ImageView的是有大小由WRAP_CONTENT定义,那么方法getMeasuredWidth()和getMeasuredHeight()看似返回0,这是使你的ImageView不可见的。

My guess is you should not call that fit() method in Picasso while your ImageView has its width and height defined by WRAP_CONTENT. This method wait until the ImageView has been measured and resize the image to exactly match its size. While your ImageView is having size defined by WRAP_CONTENT, then methods getMeasuredWidth() and getMeasuredHeight() seemingly returns 0 which is making your ImageView invisible.

这篇关于毕加索不加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆