How to reset view to original state after using animators to animates its some properties?

耗尽温柔 提交于 2019-12-06 18:33:09

问题


I am using animators (ObjectAnimator) to animate few properties (scale, rotate) of a view.

Target view is animating properly when ObjectAnimators are set to it.

But there is an added requirement to get view to the original position (reset) after a while.

I tried to cancel() the animator but it only cancels the animation and doesn't reset the view.

Possible solution : creating another animator that does just opposite of the initial animator.

Is there any other way to reset it ?


回答1:


See the solution I came up with as I had a similar issue with animations inside views in a recycler view, so I had to find a way to reset them:

Trying to reset values from Property Animator to be used in recycler view

Good news in Android O these will be better supported




回答2:


Do you mean stop a running animation? If so, call clearAnimation() to remove animations from the views that you called startAnimation(); If what you mean is to reset the view to its original appearance after the animation is over, always setFillAfter(false); to the animations.




回答3:


I met the same problem, because I animate the view use ViewPropertyAnimator, addView() and removeView() again and again for not creating new view, but a view can be shown once, when you remove the view, you call addview() again, it is no show, but you see the property visibility is visible and animationListener also be called. it is strange.



来源:https://stackoverflow.com/questions/30859572/how-to-reset-view-to-original-state-after-using-animators-to-animates-its-some-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!