Picasso not loading the image(毕加索没有加载图像)
问题描述
这是毕加索的代码:
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() 方法ImageViewWRAP_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.
这篇关于毕加索没有加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:毕加索没有加载图像
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
