码迷,mamicode.com
首页 > 移动开发 > 详细

Android动画学习(缓动动画与属性动画的区别)

时间:2015-10-16 06:21:42      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

前言:

 

在 Android动画学习(概述)中,如果你看过这篇帖子,你应该会对缓动动画和属性动画之间的区别产生疑问,因为在它们的应用中,你会感觉这两种动画有着一些相似的地方,为此,我打算把这两种动画之间的区别做一下说明

 

区别:

 

在这里先附上官方文档对于这两种动画的区别说明(我所说的缓动动画对应在下文中的英文为:View Animation,属性动画对应在下文中的英文为:Property Animation):

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.

 

从文中的英文描述来看,缓动动画和属性动画的却别主要有三点:

1.缓动动画的操作对象只能是View类型的对象,而属性动画的操作对象可以是View也可以不是View。因为缓动动画的操作对象只能是View类型的对象,所以它能操作的属性只能是View所具有的,这也导致了缓动动画相比较属性动画可应用的面要窄。

2.缓动动画在Translate属性变化的时候,如果是个Button对象,那么当它移动的时候,它的点击区域并没有随着Button的移动而移动,你如果点击它最初绘制的那个位置将会触发Click事件,而点击移动中的Button则不会触发Click事件,这个时候就需要你自己来写逻辑处理这种情况了。而属性动画则不会出现这种情况,它比缓动动画要可靠很多。在更高级的需求下,例如:颜色,位置,尺寸以及同时使用多个动画和插值器的地方,你最好使用属性动画。

最后,文中说明了一下为何要使用缓动动画,因为缓动动画只需要少量的代码就可以实现动画效果。如果缓动动画能满足你的需要,或者你现存的代码已经使用了它,那么你也无需去修改它,来使用属性动画。在一些情况下,可能会将缓动动画和属性动画混合使用。

 

相关文档:

属性动画和缓动动画的区别

https://developer.android.com/guide/topics/graphics/prop-animation.html

Android动画学习(缓动动画与属性动画的区别)

标签:

原文地址:http://www.cnblogs.com/lupiniii/p/4884133.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!