Matthias Prodani Matthias Prodani - 5 months ago 7
Java Question

Waiting for ImageView.animate() to end before proceeding with the rest of the code

I'm a beginner learning android development and I was trying to make an image switch using fade in and out animation using ImageView.animate().alpha(); what I found is that the image changed before the animation finished so no animation was seen.

my code is


ImageView image = (ImageView)findViewById(R.id.imageToChange);
image.animate().alpha(0f).setDuration(1000);
image.setImageResource(R.drawable.image2);



Thanks in advance,
Matt

Answer

For waiting for the animation end you might use this example from the Android site and setListener method.

If you want the view to become visible you need to set alpha(1f). Also, try setImageResource before animation (switch line 3 with 2).

Comments