Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ObjectAnimation only started once

I use the ObjectAnimator API (android.animation.ObjectAnimator) to animate a button once it's clicked (v is the Button):

ObjectAnimator animator = ObjectAnimator.ofFloat(v, "rotationY", 360f);
animator.setDuration(5000);
animator.start();

When I test this on the emulator, it works for the first click (button rotates). But when I click the button again (the fragment is not destroyed etc. after the first click), I don't see any animation on the emulator (the emulator isn't the fastest, but with 5 seconds I should see something).

Do I need to destroy/close something after the first animation or what am I missing? Does anyone have a hint or can reproduce this?

Thanks in advance, Martin

like image 591
hoffimar Avatar asked Nov 29 '22 17:11

hoffimar


1 Answers

The second time you will try to animate from 360.0f to 360.0f. Change your call to ofFloat() to:

ObjectAnimator.ofFloat(v, "rotationY", 0.0f, 360.0f)
like image 194
Romain Guy Avatar answered Dec 04 '22 05:12

Romain Guy