Android 动画

动画

The Android framework provides two animation systems: property animation and view animation. Both animation systems are viable options, but the property animation system, in general, is the preferred method to use, because it is more flexible and offers more features. In addition to these two systems, you can utilize Drawable animation, which allows you to load drawable resources and display them one frame after another.

Android Framework 提供了两个动画系统:属性动画和视图动画。它们都提供了可行的选项,但是一般情况下推荐使用属性动画,因为它更加灵活并且提供了更多特性。除了这两种动画系统,还可以利用 Drawable 动画来加载 drawable 资源进行一帧帧的显示。

Property Animation(属性动画)

Android 3.0(API 11)加入,属性动画让你可以给对象的属性进行 key 动画,即使是在屏幕上没渲染出来的。这套系统是可扩展的,让你也可以对自定义类型的属性进行 key 动画。

类继承关系

  • Animator
    • AnimatorSet
    • ValueAnimator
      • ObjectAnimator
      • TimeAnimator

    setStartDelay() 设置延迟播放动画

Interpolator 差值器 与 TypeEvaluator 估值器区别

The ValueAnimator encapsulates a TimeInterpolator, which defines animation interpolation, and a TypeEvaluator, which defines how to calculate values for the property being animated. For example, in Figure 2, the TimeInterpolator used would be AccelerateDecelerateInterpolator and the TypeEvaluator would be IntEvaluator.

属性动画的核心类:ValueAnimator 封装了一个 TimeInterpolator 和一个 TypeEvaluator,TimeInterpolator 规定了动画的差值,TypeEvaluator 定义了如何计算要进行动画的属性的值。
一个针对时间的变化,一个针对值得变化。

To start an animation, create a ValueAnimator and give it the starting and ending values for the property that you want to animate, along with the duration of the animation. When you call start() the animation begins. During the whole animation, the ValueAnimator calculates an elapsed fraction between 0 and 1, based on the duration of the animation and how much time has elapsed. The elapsed fraction represents the percentage of time that the animation has completed, 0 meaning 0% and 1 meaning 100%. For example, in Figure 1, the elapsed fraction at t = 10 ms would be .25 because the total duration is t = 40 ms.
[elapsed fraction 过去的时间分数(时间因子)]

自定义 Interpolator 与 TypeEvaluator

Interpolator 差值器

Interpolator

当你没有为动画设置插值器时,系统默认会帮你设置加减速插值器AccelerateDecelerateInterpolator

自定义 Interpolator ,继承 Interpolator,重写 public float getInterpolation(float input) 方法,对返回值做处理。
这里的 input 参数是[0,1]的数,0 表示开始,1 表示结束,是系统根据设置的动画时间计算出来的,从0匀速到1。

TypeEvaluator 估值器

TypeEvaluator

自定义TypeEvaluator需要重写evaluate()方法,计算对象的属性值并将其封装成一个新对象返回

重写:
public T evaluate(float fraction, T startValue, T endValue);

使用XML编写动画

参考

Animating Layout Changes to ViewGroups

Specifying Keyframes

Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
Keyframe kf1 = Keyframe.ofFloat(.5f, 360f);
Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
ObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(target, pvhRotation)
rotationAnim.setDuration(5000ms);

更多参考 MultiPropertyAnimation.java

Animating with ViewPropertyAnimator

Multiple ObjectAnimator objects

ObjectAnimator animX = ObjectAnimator.ofFloat(myView, "x", 50f);
ObjectAnimator animY = ObjectAnimator.ofFloat(myView, "y", 100f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();

One ObjectAnimator

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 50f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 100f);
ObjectAnimator.ofPropertyValuesHolder(myView, pvhX, pvyY).start();

ViewPropertyAnimator

myView.animate().x(50f).y(100f);

如果只是对 View 的一个或两个属性进行动画,使用 ObjectAnimator 就可以完成,如果想要对 View 的多个属性同时进行动画,使用 ViewPropertyAnimator 会更方便。

更多参考 blog post

View Animation(视图动画)

视图动画是一款老的动画系统,只能给 View 视图 key 动画。使用简单并且提供了足够的功能来满足一般应用的需要。

类继承关系

  • Animation
    • AlphaAnimation
    • TranslateAnimation
    • ScaleAnimation
    • RotateAnimation
    • AnimationSet

Drawable Animation(帧动画)

drawable 动画涉及一个接一个的显示 drawable 资源文件,就像播放电影。这种动画方式在你需要使用 Drawable 资源文件来做动画的情况下是非常有用的。

郭霖属性动画:http://blog.csdn.net/guolin_blog/article/details/43536355#t6
浅析Android动画 http://www.cnblogs.com/wondertwo/p/5295976.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
4S店客户管理小程序-毕业设计,基于微信小程序+SSM+MySql开发,源码+数据库+论文答辩+毕业论文+视频演示 社会的发展和科学技术的进步,互联网技术越来越受欢迎。手机也逐渐受到广大人民群众的喜爱,也逐渐进入了每个用户的使用。手机具有便利性,速度快,效率高,成本低等优点。 因此,构建符合自己要求的操作系统是非常有意义的。 本文从管理员、用户的功能要求出发,4S店客户管理系统中的功能模块主要是实现管理员服务端;首页、个人中心、用户管理、门店管理、车展管理、汽车品牌管理、新闻头条管理、预约试驾管理、我的收藏管理、系统管理,用户客户端:首页、车展、新闻头条、我的。门店客户端:首页、车展、新闻头条、我的经过认真细致的研究,精心准备和规划,最后测试成功,系统可以正常使用。分析功能调整与4S店客户管理系统实现的实际需求相结合,讨论了微信开发者技术与后台结合java语言和MySQL数据库开发4S店客户管理系统的使用。 关键字:4S店客户管理系统小程序 微信开发者 Java技术 MySQL数据库 软件的功能: 1、开发实现4S店客户管理系统的整个系统程序; 2、管理员服务端;首页、个人中心、用户管理、门店管理、车展管理、汽车品牌管理、新闻头条管理、预约试驾管理、我的收藏管理、系统管理等。 3、用户客户端:首页、车展、新闻头条、我的 4、门店客户端:首页、车展、新闻头条、我的等相应操作; 5、基础数据管理:实现系统基本信息的添加、修改及删除等操作,并且根据需求进行交流信息的查看及回复相应操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值