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

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

问题描述

这是毕加索的代码:

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 的值:http://kiagallery.ir/Images/Upload/Collection%20101/Spring%20101/d4a03b66dc7b46c694615c549b78b2e9.jpg

here's the value of _url: 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>

如您所见,可以通过浏览器访问该图像,但 picasso 无法加载它,我检查了 onError 函数,它从未被调用,我在这里很安静,任何帮助将不胜感激.

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.

推荐答案

我猜你应该在你的 中调用 Picasso 中的 fit() 方法ImageView 的宽度和高度由 WRAP_CONTENT 定义.

My guess is you should not call that fit() method in Picasso while your ImageView has its width and height defined by WRAP_CONTENT.

此方法等到 ImageView 被测量并调整图像大小以完全匹配它的大小.虽然您的 ImageView 的大小由 WRAP_CONTENT 定义,但方法 getMeasuredWidth()getMeasuredHeight() 似乎返回 0这使您的 ImageView 不可见.

This method wait until the ImageView has been measured and resize the image to exactly match it's 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天全站免登陆