Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can only animate once with Animation

Tags:

android

I have an Animation that animates properly and correct the first time I'm running it.

But in my application I have a Button and when I click on that I want to animate exactly as I did the first time, but instead its not animating at all.

Any ideas? Don't think this is code related, its seems that I'm missing something from the API.

like image 810
Curtain Avatar asked Dec 02 '22 02:12

Curtain


2 Answers

Just use getAnimation().start(); for your view. It will restart your animation.

like image 124
Vladimir Ivanov Avatar answered Dec 30 '22 20:12

Vladimir Ivanov


When you are using ViewPropertyAnimator without xlm code, you must remember that:

When you are animating a view with a rotation (or anithing else) viewElement.animate.rotate(180), you will change the viewElement attribute in this case rotation!

So if you call again viewElement.animate.rotate(180). Your element will not rotate, cause the rotation is already occured

Solution 1

myView.animate().rotation(myView.getRotation()+180);

Solution 2 (seems equivalent but is different)

myView.animate().setRotation(0);
myView.animate().rotation(180);
like image 20
Fabrizio Scarponi Avatar answered Dec 30 '22 20:12

Fabrizio Scarponi