毕加索没有加载图像

ara*_*een 14 android imageview 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() {


        }
    });
Run Code Online (Sandbox Code Playgroud)

这是_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>
Run Code Online (Sandbox Code Playgroud)

你可以看到图像可以通过浏览器访问,但毕加索无法加载它,我已经检查了onError函数,它从未被调用,我很安静地丢失在这里,任何帮助将不胜感激.

编辑:当我给imageview的宽度和高度固定值像200dp时,它加载图像,但当我将其更改为wrap_content时,它不显示图像.

Def*_*era 61

不要忘记清单的添加权限

<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" /> 
Run Code Online (Sandbox Code Playgroud)

  • 你拯救我的屁股......我无法相信毕加索不抱怨... (6认同)
  • 我的天啊!我也错过了这个! (2认同)

小智 29

我的猜测是,你应该调用fit()在毕加索的方法,而你ImageView拥有它的宽度和高度的定义WRAP_CONTENT.

此方法等到ImageView测量完毕并调整图像大小以与其大小完全匹配.当你的ImageView是具有由定义的大小WRAP_CONTENT,然后方法getMeasuredWidth()getMeasuredHeight()看似返回0,其使你ImageView 不可见.

  • 我有完全相同的代码,但它仍然没有加载它.我已经将宽度和高度更改为200dp并添加了Manifest File的权限,可能出现的问题是什么? (2认同)