Picasso: Image not loading in RecyclerView

Created on 5 Feb 2016  Â·  16Comments  Â·  Source: square/picasso

HI,
I'm trying to load list of images from server in to a recycler view, some images are not loading. but when I try to load it in an ImageView that is not in a RecyclerView it load's perfectly. one effected image I uploaded here.

my code is :

                Picasso.with(mContext).load(imageUrl)
                        .transform(new RoundedRectTransformation(cornerRadius, 0))
                        .fit().centerCrop().into(viewHolderOffer.mOfferImage);

I have saw issue reported for older version of Picasso, but I'm using the latest version 2.5.2

Most helpful comment

I am also having issues with Picasso loading images in a RecyclerView.

When I run Picasso.with(mImageView.getContext()).load(mPhotoUri).resize(37, 37).into(mImageView); or Picasso.with(mImageView.getContext()).load(mPhotoUri).noFade().into(mImageView);

The ImageView is simply blank. Like it never loaded.

Then when I run Picasso.with(mImageView.getContext()).load(mPhotoUri).noFade().placeholder(R.drawable.placeholder).into(mImageView); (same thing with placeholder image) I get an imageview with the placeholder, but image does not load.

I debugged the app to see value of mPhotoUri then did an adb pull on that path with success. Image does exist.

I also replaced the Picasso line with mImageView.setImageBitmap(UriUtil.getBitmapFromUri(photo)); where UriUtil.getBitmapFromUri() is:

    public static Bitmap getBitmapFromUri(Uri uri) {
        File image = new File(uri.getPath());

        return BitmapFactory.decodeFile(image.getAbsolutePath());
    }

and this works. Image loads no problem. However, it doesn't look good because its not centered, fitted, etc. like I want Picasso to do for me.

Here is my ImageView

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

       <ImageView
        android:id="@+id/image_for_picasso"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_placeholder" />

</merge>

I am using merge here for a custom view I'm setting inside of the RecyclerView row.

All 16 comments

I have a similar problem when using .fit() image doesn't loaded into ImageView...
When I using only .load() and .into() image is showing.
mPicasso.load(file).into(holder.imageView) - works
mPicasso.load(file).fit().centerInside().into(holder.imageView) - dosn't work

Edit: resize() also works

Can you try the 2.6.0-SNAPSHOT?

I tried, but I'm not sure I did everything right, because this dir: 'com.squareup.picasso:picasso:2.6.0-SNAPSHOT' in gradle didn't work... So I downloaded this file: picasso-2.6.0-20160130.024438-1.jar, added to the project, but nothing has changed. It is not a big problem for me, because resize() works, but fit() has strange behavior, because there are no results for Callback (onSuccess, onError) and no results for onImageLoadFailed

@matos2007, @iamshajeer what does your layout look like? I've tried to replicate your issue with the layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/photo_thumbnail_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="?android:attr/selectableItemBackground"
    android:orientation="vertical">
    <ImageView
        android:id="@+id/photo_thumbnail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/darker_gray"/>
</FrameLayout>

and

Picasso.with(iv.getContext())
            .load(imageUrl)
            .fit()
            .centerCrop()
            .into(holder.photo_thumbnail);

with no issues.

Sorry, I don't have much time. I created repo with my example, maybe this helps:
https://github.com/matos2007/picassoTest

In MainActivity change folder with image, and in AdapterClass change resize() to fit() and see if it works.

@matos2007

You're trying to fit to an imageview doesn't contain a default image source but is using wrap_content on the imageview width and height. Try putting a default placeholder image in your layout.

@JohnWowUs my layout is little complicated, but its looks like

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="273dp">

            <ImageView
                android:id="@+id/offer_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
....
....
....
</RelativeLayout>


As I said for some images it loads perfectly. but few are having the issue. 
@JohnWowUs can you try with the exact image that I've posted ?

@JakeWharton I din't try snapshot version, can you give me the gradle url ? or any links , explains about the snapshot version ?

@JohnWowUs I set imageView layout_height to ?listPreferredItemHeight and it's works! Thank you.
I thought that this value gets from RelativeLayut... Stupid mistake. Sorry :)

@iamshajeer

If you use fit() and any of your imageview dimensions are 0 after the layout is measured then picasso won't even try to load the image

See (with added comments)

 @Override public boolean onPreDraw() {
    ImageView target = this.target.get();
    if (target == null) {
      return true;
    }
    ViewTreeObserver vto = target.getViewTreeObserver();
    if (!vto.isAlive()) {
      return true;
    }

    int width = target.getWidth();
    int height = target.getHeight();

   if (width <= 0 || height <= 0) {
      // If any of the measured dimensions are <= 0 then picasso does nothing
      return true;
    }

    vto.removeOnPreDrawListener(this);
    this.target.clear();

    // Picasso asks for a resize to the measured dimensions 
    // and submits the request to load the image into the imageview
    this.creator.unfit().resize(width, height).into(target, callback);
    return true;
  }

in https://github.com/square/picasso/blob/master/picasso/src/main/java/com/squareup/picasso/DeferredRequestCreator.java

PS: I've tried your exact image and it works with 2.5.2 on a recyclerview

I am also having issues with Picasso loading images in a RecyclerView.

When I run Picasso.with(mImageView.getContext()).load(mPhotoUri).resize(37, 37).into(mImageView); or Picasso.with(mImageView.getContext()).load(mPhotoUri).noFade().into(mImageView);

The ImageView is simply blank. Like it never loaded.

Then when I run Picasso.with(mImageView.getContext()).load(mPhotoUri).noFade().placeholder(R.drawable.placeholder).into(mImageView); (same thing with placeholder image) I get an imageview with the placeholder, but image does not load.

I debugged the app to see value of mPhotoUri then did an adb pull on that path with success. Image does exist.

I also replaced the Picasso line with mImageView.setImageBitmap(UriUtil.getBitmapFromUri(photo)); where UriUtil.getBitmapFromUri() is:

    public static Bitmap getBitmapFromUri(Uri uri) {
        File image = new File(uri.getPath());

        return BitmapFactory.decodeFile(image.getAbsolutePath());
    }

and this works. Image loads no problem. However, it doesn't look good because its not centered, fitted, etc. like I want Picasso to do for me.

Here is my ImageView

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

       <ImageView
        android:id="@+id/image_for_picasso"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_placeholder" />

</merge>

I am using merge here for a custom view I'm setting inside of the RecyclerView row.

I also have the same issue but only with Samsung Tab 6.0.1 Android version, exactly same problem as @levibostian . Everything is working fine on Samsung Galaxy S4 and Nexus 5.

In my case the problem is Android 6.0 required runtime permission for "Read External Storage", hence accessing resolved the problem. But on part of Picasso, it doesn't show me any error or log, I think it should check from ImageView if the image is successfully showed and then log it. Otherwise this Android 6.0+ silently stops if no permissions are granted.

I already have read external permissions on my app.

On Thu, Oct 6, 2016 at 8:06 AM Ahmad Ali [email protected] wrote:

In my case the problem is Android 6.0 required runtime permission for
"Read External Storage", hence accessing resolved the problem. But on part
of Picasso, it doesn't show me any error or log, I think it should check
from ImageView if the image is successfully showed and then log it.
Otherwise this Android 6.0+ silently stops if no permissions are granted.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/square/picasso/issues/1291#issuecomment-251955698,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB8k-vi3m64O01Hlgz2Kh1ewnBWWCuRPks5qxPJngaJpZM4HUIiD
.

Android Manifest permissions are not enough. You need to get runtime permissions on Android 6.0+ or allow permissions by going to Settings->Permissions and grant permissions to your app.
https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

Correct. I have permissions accepted by the user.

On Thu, Oct 6, 2016 at 9:20 AM Ahmad Ali [email protected] wrote:

Android Manifest permissions are not enough. You need to get runtime
permissions on Android 6.0+ or allow permissions by going to
Settings->Permissions and grant permissions to your app.

https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/square/picasso/issues/1291#issuecomment-251976568,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB8k-hGCo9hwHv-v1VhgupzUyJ_dieaeks5qxQO1gaJpZM4HUIiD
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bersh picture Bersh  Â·  18Comments

leolanzinger picture leolanzinger  Â·  37Comments

julianonunes picture julianonunes  Â·  26Comments

riclage picture riclage  Â·  23Comments

justingarrick picture justingarrick  Â·  42Comments