Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load from URL to ImageView with Picasso without white flash on ImageView

I'm using the Picasso library from Square to load a URL string into an ImageView. I'm calling this several times on an array or URLs with a Timer to change the ImageView image.

The first time though, when Picasso is loading the URL content, every time the ImageView updates, it flashes white.

After Picasso caches the content, the ImageView changes without the flash.

How do I stop the ImageView from flashing white?

Picasso.with(getApplicationContext()).load(currentUrl).into(img, new Callback() {
                    @Override
                    public void onSuccess() {
                        mProgress.dismiss();
                    }

                    @Override
                    public void onError() {
                        mProgress.dismiss();
                    }
                });
like image 438
bodagetta Avatar asked May 26 '15 19:05

bodagetta


People also ask

How do you load an image into an ImageView from an image URL using Picasso?

Image loading using Picasso is very easy, you can do it like this way Picasso. get(). load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.


1 Answers

Had the same issue, solved it by adding the noPlaceHolder instruction like this :

Picasso.with(getApplicationContext())
    .load(currentUrl)
    .noPlaceholder()
    .into(img, new Callback() {
                    @Override
                    public void onSuccess() {
                        mProgress.dismiss();
                    }

                    @Override
                    public void onError() {
                        mProgress.dismiss();
                    }
                });

By default, Picasso will either clear the target ImageView in order to ensure behavior in situations where views are recycled. This method will prevent that behavior and retain any already set image.

Picasso Documentaton

like image 73
AdrienG Avatar answered Oct 21 '22 11:10

AdrienG