Picasso: Q: Keep old image while newest one is loading

Created on 14 Sep 2013  路  6Comments  路  Source: square/picasso

Hi!

I have a View which change his image each certain period. When I change the image, the old one is deleted from the view and the placeholder is shown (if has, else show nothing), and after load, the new image is shown. This behaviour happens even with noFade(). I need to find a way to keep showing the first image while the second one is loaded, and then show it immediately. Is this possible?

Thanks in advance,

Regards!

Most helpful comment

One thing that I've done to effectively cross-fade between images in a single ImageView is to set the placeholder to be the ImageView's current image.

So, say I had an ImageView called myImageView that I've already loaded an image into and I want to load a new image from the Uri myUri:

Picasso.with(context)
  .load(myUri)
  .placeholder(myImageView.getDrawable())
  .into(myImageView);

If I understand your question correctly then you could try the above and also add noFade() and it should instantly switch between images when the new image is available.

All 6 comments

You could a single background thread and call get() to retrieve the bitmap synchronously, once you have a bitmap at this point you can do whatever you wish with it.

In other words, use Picasso for its loading and decoding capabilities and build around it. Its not that much code.

One caveat. Using get() won't add the images to Picassos cache.

edit: From what I understand you just need to invoke Picasso without placeHolder() the second time around...At least I think thats what you are trying to do.

One thing that I've done to effectively cross-fade between images in a single ImageView is to set the placeholder to be the ImageView's current image.

So, say I had an ImageView called myImageView that I've already loaded an image into and I want to load a new image from the Uri myUri:

Picasso.with(context)
  .load(myUri)
  .placeholder(myImageView.getDrawable())
  .into(myImageView);

If I understand your question correctly then you could try the above and also add noFade() and it should instantly switch between images when the new image is available.

The solution offered by HayH5 works like a charm :D. Thanks!!!!!!

place holder isn't working for vector drawables <= 21 API, but Android default method works fine for such APIs mImageView.setImageResource(R.drawable.vector_drawable_image);, Why??

because Picasso uses weird method:

private Drawable getPlaceholderDrawable() {
    if (placeholderResId != 0) {
      return picasso.context.getResources().getDrawable(placeholderResId);
    } else {
      return placeholderDrawable; // This may be null which is expected and desired behavior.
    }
  } 

JayH5 , if I understood correctly that s a very good idea., thx a lot.
But how can you set the imageResource taken from Url at the first place?

For example
imageView = findViewById(R.id.myimage);
imageView.setImageResource(photo1.getUrls().getRegular()); --here I ve a problem!!
Picasso.with(MainActivity.this).load(photo1.getUrls().getRegular()).placeholder(imageView.getDrawable()).fit().into(imageView);

Was this page helpful?
0 / 5 - 0 ratings