遇到一个项目需求,想让动画变得更活泼一点,于是想到了动画属性中的Interpolator,写了基本例子测试一下Android提供给我们现成的加速器的效果:
效果 | 代码中方法 | xml中属性 |
---|---|---|
越来越快 | AccelerateInterpolator() | @android:anim/accelerate_interpolator |
越来越慢 | DecelerateInterpolator() | @android:anim/decelerate_interpolator |
先快后慢 | AccelerateDecelerateInterpolator() | @android:anim/accelerate_decelerate_interpolator |
先后退一小步然后向前加速 | AnticipateInterpolator() | @android:anim/anticipate_interpolator |
快速到达终点超出一小步然后回到终点 | OvershootInterpolator() | @android:anim/overshoot_interpolator |
到达终点超出一小步然后回到终点 | AnticipateOvershootInterpolator() | @android:anim/anticipate_overshoot_interpolator |
弹球效果,弹几下回到终点 | BounceInterpolator() | @android:anim/bounce_interpolator |
均匀速度 | LinearInterpolator() |
@android:anim/linear_interpolator |
在实现动画的非线性变化的方法中,常用的一种是为动画添加插值器以改变视图的属性值,从而实现理想的动画效果。Interpolator使用相对简单,下面就只给出一些提供的插值器的默认效果。
在代码中:直接调用AccelerateInterpolator());
Android:interpolator="@android:anim/"
android:shareInterpolator="true"
x < 0.3535< 0.7408< 0.9644)
(x-1.0435)* (x-1.0435)* 8+0.95 (x = 其他)
AnticipateInterpolator:
x * x * ((2+ 1) * x - 2)
AccelerateDecelerateInterpolator:
(cos((x+ 1) * π) / 2.0) + 0.5
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/6bccd507235c4335a7b0bdf41a4167be/acceleratedecelerateinterpolator.gif)
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/6bccd507235c4335a7b0bdf41a4167be/acceleratedecelerateinterpolator.gif)
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/24d079c511a441638c3953440b6e34f4/accelerateinterpolator.gif)
< 0.5)
0.5*((2*x-2) * (2*x-2) * ((3 + 1) * (2*x-2) + 3)+2) (0.5 <= x < 1.0)
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/dbca6f31640f49688ecb3f1ceb3cb98d/anticipateovershootinterpolator.gif)
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/dbca6f31640f49688ecb3f1ceb3cb98d/anticipateovershootinterpolator.gif)
DecelerateInterpolator:
1.0 - pow((1.0 - x), 2 * 1)
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/fc54c19d2b3e495db31d5c4d0d9fc2f8/decelerateinterpolator.gif)
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/75383586e9434dbca7bcdfca67d604bf/linearinterpolator.gif)
OvershootInterpolator:
(x-1) * (x-1) * ((2+ 1) *( x-1) + 2)+1
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/b939df8ede6a4d3a9df0bcddf81eae68/overshootinterpolator.gif)
![](file:///C:/Users/Administrator/AppData/Local/YNote/data/sina2814270121/b939df8ede6a4d3a9df0bcddf81eae68/overshootinterpolator.gif)