【译】Android API Guide 之 属性动画

来源:互联网 发布:淘宝c店还可以赚到钱吗 编辑:程序博客网 时间:2024/05/22 13:14

属性动画与View Animation的区别

View Animation(下简称va)只针对view对象使用,对于其他非view类对象,开发者只能自行实现。并且va只提供有限几种动画方式,比如缩放、转动。并不支持对背景色的动画修改。
va的另外一个劣势:va在动画过程中仅仅是重新绘制了view,而对于view的其他属性比如点击区域并未进行修改。比如一个button,使用va进行了位移,实际上动画完成后,该button的点击区域仍然在原始位置上,而非移动之后的位置。

属性动画可以完全突破以上的限制,你可以通过它完成对任何对象的任何属性的修改,对,这里修改的是对象本身的属性。属性动画系统产生动画的方式鲁棒性更强。进阶的做法,你可以给对象的属性赋予任意的动画,比如颜色,位置,大小,并且可以定义动画的 interpolation and synchronization

How Property Animation Differs from View Animation


The view animation system provides the capability to only animate View objects, so if you wanted to animate non-View objects, you have to implement your own code to do so. The view animation system is also constrained in the fact that it only exposes a few aspects of a View object to animate, such as the scaling and rotation of a View but not the background color, for instance.

Another disadvantage of the view animation system is that it only modified where the View was drawn, and not the actual View itself. For instance, if you animated a button to move across the screen, the button draws correctly, but the actual location where you can click the button does not change, so you have to implement your own logic to handle this.

With the property animation system, these constraints are completely removed, and you can animate any property of any object (Views and non-Views) and the object itself is actually modified. The property animation system is also more robust in the way it carries out animation. At a high level, you assign animators to the properties that you want to animate, such as color, position, or size and can define aspects of the animation such as interpolation and synchronization of multiple animators.

The view animation system, however, takes less time to setup and requires less code to write. If view animation accomplishes everything that you need to do, or if your existing code already works the way you want, there is no need to use the property animation system. It also might make sense to use both animation systems for different situations if the use case arises.

0 0
原创粉丝点击