Loading from url to ImageView using Picasso without white flash on ImageView

I am using the Picasso library from Square to load a URL string into an ImageView. I call this multiple times on an array or url with a timer to change the ImageView's image.

The first time Picasso loads the content of the url, every time the ImageView is refreshed, it blinks white.

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

How do I stop an ImageView from being white?

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

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

      

+3


source to share


1 answer


Had the same problem, solved it by adding a noPlaceHolder statement 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 to provide behavior in situations where the views are refactored. This method will prevent this behavior and keep any already set image.

Picasso documentary

+13


source







All Articles