Animator 和 Animation 有什么区别? [英] What is the difference between an Animator and an Animation?

查看:21
本文介绍了Animator 和 Animation 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它看起来像 AnimationsAnimators 允许我为对象的属性(位置、不透明度、缩放、旋转等)设置动画,我很难区分两者的用例.我什么时候应该使用动画师和动画,反之亦然?

It looks like both Animations and Animators allow me to animate properties (position, opacity, scale, rotation, etc) on objects, and I'm having a hard time differentiating between the use case for both. When should I use an animator versus an animation and vice versa?

推荐答案

AnimationsAnimators 的旧版本.Animators 在 3.0 中引入,以帮助克服 Animations 的一些缺点.

Animations are older versions of Animators. Animators where introduced in 3.0 to help overcome some short-coming that Animations have.

Animations 只改变对象的视觉表现.如果您只是更改不透明度,这很好,但在您平移、旋转或缩放对象时会导致问题.在 Animators 出现之前的旧时代,如果您平移对象,则必须使用新坐标执行重新布局.根据物体移动的位置,这可能相当困难.

Animations only change the visual representation of an object. This is fine if you're just changing opacity, but it causes issues when you translate, rotate, or scale objects. In the old days before Animators, if you translated the object, you had to perform a re-layout with the new coordinates. It could be rather difficult depending on where the object moved.

另一方面,动画师会改变对象的物理属性.这意味着如果您将 View 移动到新位置,则触摸坐标将映射到新位置,无需任何其他干预.

Animators on the other hand change the physical properties of the objects. This means that if you move a View to a new location, the touch coordinates will be mapped at the new location without any other intervention.

就我个人而言,除非我在 API 2.3 或更低版本上进行开发,否则我不再经常使用动画.值得庆幸的是,这已经不是什么问题了.还有一些旧的类仍然使用动画 API,尤其是在使用 xml 资源时,例如 android.support.v4.app.FragmentTransaction 类(普通的 FragmentTransaction改为支持动画师).

Personally, I don't use Animations much anymore unless I'm developing at API's 2.3 or less. Thankfully that's becoming less of an issue. There are also some old classes that still use Animations API especially when it comes to using xml resources such as the android.support.v4.app.FragmentTransaction class (the normal FragmentTransaction supports Animators instead).

顺便提一下,NineOldAndroids 项目的开发是为了模仿 Animators 的功能,但使用动画制作应用程序一直工作到 1.6.

As a side note, the project NineOldAndroids was developed to mimic functionality of Animators but using Animations so you can make apps that work all the way to 1.6.

这篇关于Animator 和 Animation 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆