praxmon
praxmon

Reputation: 5121

Picasso placeholder image animation

I am trying to load an image into an ImageView using picasso. The code is given below:

Picasso.with(this)
       .load(imageURL)
       .placeholder(drawable1)
       .error(drawable1)
       .into(imageview)

Now here while picasso is waiting for the download to complete, the imageview goes blank. To prevent that I want to fade out the current image to a drawable and then to load the image present in the URL. Is there any way to do this?

Upvotes: 2

Views: 2952

Answers (2)

ap6491
ap6491

Reputation: 835

You can define the fade out animation in an XML like this:

<?xml version="1.0" encoding="UTF-8"?>
       <set xmlns:android="http://schemas.android.com/apk/res/android">
         <alpha android:fromAlpha="1.0" android:toAlpha="0.0" 
          android:interpolator="@android:anim/accelerate_interpolator" 
          android:duration="2000"/>
     </set>

Then, you can load the animation using:

Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.your_fade_in_anim);
    imageView.startAnimation(fadeoutAnim);

Upvotes: 0

Weibo
Weibo

Reputation: 1042

I think Picass has done this for you, placehoder drawable is used to be shown when image is being loaded, and the error drawable will be shown when image load failed.

If you want to really to do some thing you can use Target as following:

new Target() {
  @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
    imageView2.setImageBitmap(bitmap);
   }

   @Override public void onBitmapFailed(Drawable errorDrawable) {

   }

   @Override public void onPrepareLoad(Drawable placeHolderDrawable) {

   }
}

Upvotes: 1

Related Questions