简体   繁体   English

动画LayoutParams与Android中的翻译和缩放

[英]Animating LayoutParams vs. Translation and Scale in Android

It seems like the code for animating a view's scale and translation is always much more clean and concise (eg using .animate() ) than code that animates the view's LayoutParams (ie width, height, etc.) which requires the use of animators ( ValueAnimator , ObjectAnimator , etc.) 似乎动画视图的比例尺和平移的代码总是比需要使用动画器的动画(例如, .animate() )更简洁明了(例如,使用.animate() )。 ValueAnimatorObjectAnimator等)

That made me wonder whether animating a certain view's LayoutParams is considered a bad practice, or if it's "heavier" than animating the view's translation and scale properties? 这使我想知道,对某个视图的LayoutParams进行动画处理是否被认为是不好的做法,还是比对视图的平移和缩放属性进行动画处理“重”?

Also, couldn't find any answers for this on SO so it would be great if anyone could shed some light on the subject. 另外,在SO上找不到任何答案,因此,如果有人可以对这个问题有所了解,那就太好了。

如@pskink所述,在活动/片段/布局内执行转场和动画的一种更干净的方法是使用场景和转场,这正是我所做的,并且经过一些调整才可以完美地工作!

如果您具有更复杂的布局,并尝试通过layoutParams进行动画处理,您将很快看到结结,因为在每一帧上都会触发requestLayout()并且父ViewGroup必须为整个视图层次结构执行onMeasure()onLayout()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM