android studio
属性动画的关键字·Duration 动画的持续时间;·Time Interpolation 时间插值器 计算流逝的时间·Repeat Count & Behavior 重复次数与行为·Animator sets 属性动画集 同时/顺序播放一个或多个动画·Frame fresh delay 动画的刷新时间 默认的刷新时间 10ms
三、如何计算属性动画扩展:使用动画有三个重要的要素,开始位置、结束位置、持续时间;案例一:从0px -- > 40px,匀速(线性)移动,持续的时间:40ms; LinearInterpolator 线性插值器
案例二:从0px --> 40px,先加速后减速(非线性)移动,持续时间40ms;AccelerateDecelerateInterpolator
计算(第二个位置,即t = 10ms)第一步:计算流逝因子: elapsed fraction = 10ms / 40ms = 0.25第二步:计算插值因子:interpolated fraction = (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f = 0.14644662第三步:计算属性值:property value = (int)(startInt + fraction * (endValue - startInt))= (int)(0 + 0.14644662) * (40 - 0) = 6;
在计算之前,先介绍一下属性动画中一个重要的类:Value Animator
计算过程:首先需要调用start()方法,在这个动画的过程中,Value Animator 它首先会去计算elapsed fraction(流逝因子),其值的范围是0%-100%之间,它的计算是 elapsed fraction = elapsed time / duration ;然后Value Animator就会调用TimeInterpolator去计算interpolated fraction(插值因子),它会将前面计算的时间因子作为参数传递给相应的插值器,计算出插值因子;当计算完插值因子之后,就会调用TypeEvaluator(类型估计器),将插值因子作为参数来计算动画的属性值。
属性动画中重要的类ValueAnimator、ObjectAnimator、AnimatorSetTypeEvaluator分类:IntEvaluator、FloatEvaluator、ArgbEvaluator,如果需要自定义估值器,则继承TypeEvaluator。Time Interpolator 插值器:如果你需要自定义插值器,继承TimeInterpolator;插值器的介绍:http://www.cnblogs.com/mengdd/p/3346003.html
ValueAnimatorValueAnimator down = ValueAnimator.ofFloat(0f,300f); down.setTarget(iv_android); down.setDuration(2000); down.start();
The previous code snippets, however, has no real effect on an object, because the ValueAnimator does not operate on objects or properties directly.如上代码是没有效果的,因为ValueAnimator它只负责计算属性的值,不负责操作对象或者属性。因此如果用户需要知道ValueAnimator的计算结果,那么我们就需要给ValueAnimator添加监听(Listener)。