开发者

Can only animate once with Animation

开发者 https://www.devze.com 2023-02-18 15:39 出处:网络
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开发者_如何学Go when I click on that I want to animate exactly as I did

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开发者_如何学Go 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.


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


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


set v.startAnimation(animation); instead of v.setAnimation(animation); its working for me


I had the same problem (animation appeared only once) and getAnimation().start(); unfortunately did not work. I solved it by invoking clearAnimation() on that view object and after that I set that anim again. It doesn't look like the most elegant and efficient solution, but at least works...


Might help someone, but my issue had to do with setting android:animateLayoutChanges="true" on my parent view. Once I removed that, my views started animating multiple times again. Must be some weird animation overriding thing.


Just Try This Way. I solved this and now Its working for me

 nextAnimObject= AnimationUtils.loadAnimation(getActivity(), R.anim.animation_layout);
 layout.clearAnimation();
 layout.setAnimation(nextAnimObject);
 layout.getAnimation().start();


I have another solution.

viewElement.animate.rotate(180);

The comment above says that viewElement.animate.rotate(180) is done once. But rotationBy(180) is actually performed relative to the object's current position.

0

精彩评论

暂无评论...
验证码 换一张
取 消