2

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?

praxmon
  • 5,009
  • 22
  • 74
  • 121

2 Answers2

1

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) {

   }
}
Weibo
  • 1,042
  • 8
  • 18
  • So `onPrepareLoad()` I can define the animation that I want? – praxmon Jan 27 '16 at 08:48
  • @PrakharMohanSrivastava I think you do the animation onBitmapLoaded, it will show the placeholder drawable when the image haven't loaded and the image will be changed onBitmapLoaded, and add the extra animation during the image change. But from my point of view, the animation is not necessary, you can take a look the real effect when you use picasso to show the image. – Weibo Jan 27 '16 at 09:02
0

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);
ap6491
  • 805
  • 1
  • 10
  • 26