目录
什么是Interpolator?
通俗易懂的说,Interpolator(插值器)负责控制动画变化的速率,使得基本的动画效果能够以匀速、加速、减速、抛物线速率等各种速率变化。
入口:Android 属性动画(Property Animation) 使用详解
入口:android动画——属性动画(Property Animation)
在动画开发过程中,经常需要使用到插值器来满足我们的动画设计需求。然而,官方提供的插值器并不能满足所有的需求,所以我们需要自定义插值器。
官方提供的插值器有哪些呢?
官方内置了9钟插值器:LinearInterpolator(线性插值器:匀速)、AccelerateInterpolator(加速度插值器: 起始速度慢,然后越来越快)、DecelerateInterpolator(减速插值器:起始速度快,然后越来越慢)等等。
想要详细了解官方提供的插值器,可以去看以下几位老兄的博客。
再谈属性动画——介绍以及自定义Interpolator插值器
Android 属性动画 常用方法 与 插值器 Interpolator
android 动画系列 (2) - interpolator 插值器
几种常用的Interpolator(插值器)的动画效果
这边只简单搬运一下前四个:
1.Linear Interpolator / 线性插值器
公式: y=kt
(1)任何物理量对时间的导数都是该物理量随时间的变化率。位移对时间的导数是速度,而速度对时间的导数是加速度。
(2)函数y=f(x)在x0点的导数f’(x0)的几何意义:表示函数曲线在点P0(x0,f(x0))处的切线的斜率(导数的几何意义是该函数曲线在这一点上的切线斜率)。
根据上述可知,你可以直接求导,斜率=k,且始终保持不变,匀速行驶。
也可以观测图像在每一点的切线的斜率。
2.Accelerate Interpolator / 加速度插值器
公式: y=t^(2f)描述: 加速度参数. f越大,起始速度越慢,但是速度越来越快。
3.Decelerate Interpolator / 减速插值器
公式: y=1-(1-t)^(2f)描述: 加速度参数. f越大,起始速度越快,但是速度越来越慢
4.Accelerate Decelerate Interpolator / 先加速后减速插值器
公式: y=cos((t+1)π)/2+0.5
官方插值器AccelerateDecelerate Interpolator的验证
1.代码
ValueAnimator mAnimator = ValueAnimator.ofFloat(1.0f, 5.0f).setDuration(800);
mAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Log.e("Rachel_test", "controlLeft: " + animation.getAnimatedValue());
}
});
mAnimator.start();
2.ctrl+alt复制数据
1.0
1.0
1.0772363
1.1739753
1.2324686
1.3029796
1.3819662
1.4690335
1.5582927
1.6597944
1.7679892
1.8758329
1.9954689
2.1201217
2.249169
2.3745017
2.5102313
2.6484075
2.7805316
2.9214802
3.0628214
3.203849
3.3361187
3.4745245
3.6105597
3.7362492
3.8657446
3.9909172
4.1111403
4.219599
4.328505
4.430776
4.520812
4.6087513
4.688656
4.7601266
4.8195605
4.8736496
4.9183817
4.9518337
4.9777727
4.9938345
4.9999385
5.0
3.拷贝数据到excel
=A2-A1
4.结果
很明显可以看出来,这是一个加速后又减速的插值器
实践:项目背景
UI小姐姐让实现一个类似于下面动图的动画。