Android 四种特殊Interpolator源码解析

Stella981
• 阅读 559

源博客链接:http://linkyan.com/2013/06/animation-interpolator/

今天介绍4种动画插值器

  1. OvershootInterpolator: "Overshoot" means 冲过头了,模拟了冲过了头回滚一点的效果
  2. AnticipateInterpolator:“Anticipate” means 抢先,模拟了出发前先后退一步再前冲的动画效果
  3. AnticipateOvershootInterpolator:以上两种的结合
  4. BounceInterpolator:"Bounce" means 弹跳, 就是模拟了自由落地后回弹的效果

##OvershootInterpolation

先来看Overshoot的实现的数学公式,mTension默认值为2.0f,有一个构造函数可以进行设置。

public float getInterpolation(float t) {
    t -= 1.0f;
    return t * t * ((mTension + 1) * t + mTension) + 1.0f;
}

如果带入默认值,简化下就是

y=3t^3+2t^2+1  // t:[-1~0]

然后去google搜索一下"3t^3+2t^2+1",就能看到下面这个曲线图

Android 四种特殊Interpolator源码解析

我们改下参数mTension,就能发现mTension越大,冲过的距离越大,效果越明显!

##AnticipateInterpolation

再看下Anticipate的实现数学公式,mTension同样默认是2.0f:

public float getInterpolation(float t) { 
    return t * t * ((mTension + 1) * t - mTension);
}

于是带上实际参数2.0f,得到

y=3t^3-2t^2 //t:[0~1.0]

Android 四种特殊Interpolator源码解析

同样的结论:mTension越大,抢先动画约长,效果越明显!

##BounceInterpolator

从源码我们能发现,实现方式是根据时间t,模拟了一次自由落体运动,所以Google这次帮不了我们了。

private static float bounce(float t) {
    return t * t * 8.0f;
}

public float getInterpolation(float t) {
    t *= 1.1226f;
    if (t < 0.3535f) return bounce(t);
    else if (t < 0.7408f) return bounce(t - 0.54719f) + 0.7f;
    else if (t < 0.9644f) return bounce(t - 0.8526f) + 0.9f;
    else return bounce(t - 1.0435f) + 0.95f;
}
点赞
收藏
评论区
推荐文章
Wesley13 Wesley13
2年前
ANDROID文件关联之MIME TYPE
ANDROID文件关联之MIMETYPE(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.cnblogs.com%2FGreenwood%2Farchive%2F2011%2F06%2F13%2F2079964.html)
Stella981 Stella981
2年前
ExtJs xtype 类型
ExtJsxtype一览(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.cnblogs.com%2Fxusir%2Farchive%2F2013%2F01%2F17%2F2864691.html)
Wesley13 Wesley13
2年前
MySQL redo与undo
文章转载来自:http://www.cnblogs.com/Bozh/archive/2013/03/18/2966494.html(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.cnblogs.com%2FBozh%2Farchive%2F2013%2F03%2F18%2F29
Stella981 Stella981
2年前
Qt Mac OS、iOS和X11的Retina显示支持
MacOS、iOS和X11的Retina显示支持(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fblog.qt.digia.com%2Fcn%2F2013%2F05%2F02%2Fretinadisplaysupportformacosiosandx11%2F)
Wesley13 Wesley13
2年前
P2P技术揭秘.P2P网络技术原理与典型系统开发
Modular.Java(2009.06)\.Craig.Walls.文字版.pdf:http://www.t00y.com/file/59501950(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.t00y.com%2Ffile%2F59501950)\More.E
Stella981 Stella981
2年前
Chrome DevTools:在 Profile 性能分析中显示原生 javascript 函数
本文翻译自ChromeDevTools:ShownativefunctionsinJSProfile(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.mattzeunert.com%2F2016%2F08%2F06%2Fshownativefunctionsi
Wesley13 Wesley13
2年前
JAVA 中为什么String 是immutable的
本文翻译自:http://www.programcreek.com/2013/04/whystringisimmutableinjava/(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.programcreek.com%2F2013%2F04%2Fwhystring
Stella981 Stella981
2年前
Azure EA (1) 查看国内Azure账单
《WindowsAzurePlatform系列文章目录(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.cnblogs.com%2Fthreestone%2Farchive%2F2012%2F01%2F06%2F2382322.html)》本文介绍的是国内
Easter79 Easter79
2年前
Swift项目兼容Objective
!456.jpg(http://static.oschina.net/uploads/img/201509/13172704_1KcG.jpg"1433497731426906.jpg")本文是投稿文章,作者:一叶(博客(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2F00red
Stella981 Stella981
2年前
POJ 1195 Mobile phones(二维树状数组)
题目链接:http://poj.org/problem?id1195(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fpoj.org%2Fproblem%3Fid%3D1195)题意是有四种操作。当n0时:输入一个m表示初始化矩阵(m\m且值都为0)。