-2

Let's say i have the following code:

img1.animate().alpha(.5f).setDuration(300);

And I want to execute this whenever the animation is over

img1.setImageReasource(R.drawble.img_guitar);

How do I do that??

Mayur Kharche
  • 717
  • 1
  • 8
  • 27
Eddie
  • 171
  • 5
  • 13
  • Possible duplicate of [Android Animation Listener](http://stackoverflow.com/questions/7609974/android-animation-listener) – azizbekian Apr 27 '17 at 05:11

1 Answers1

1

You can add a listener to your animation:

imageView.animate().setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        imageView.setImageResource(R.drawable.img_guitar);
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});

You can also use withActionEnd(Runnable):

imageView.animate().withEndAction(new Runnable() {
    @Override
    public void run() {
        imageView.setImageResource(R.drawable.img_guitar);
    }
})
Nicolas
  • 6,611
  • 3
  • 29
  • 73