Android源码中,有两个Interpolator。一个是frameworks/base/graphics/java/android/graphics/Interpolator.java。另一个是
frameworks/base/core/java/android/view/animation/Interpolator.java。今天想要聊的是后者。

frameworks/base/core/java/android/view/animation/Interpolator.java的源码如下:

/** * An interpolator defines the rate of change of an animation. This allows * the basic animation effects (alpha, scale, translate, rotate) to be  * accelerated, decelerated, repeated, etc. */public interface Interpolator extends TimeInterpolator {    // A new interface, TimeInterpolator, was introduced for the new android.animation    // package. This older Interpolator interface extends TimeInterpolator so that users of    // the new Animator-based animations can use either the old Interpolator implementations or    // new classes that implement TimeInterpolator directly.}

Android在3.0引入属性动画时,加入了TimeInterpolator接口。Interpolator变成与之(TimeInterpolator)对应的旧接口。Interpolator继承TimeInterpolator,可以兼容旧代码。建议开发者在开发新代码的时候,直接实现TimeInterpolator接口。所以,我们需要再看一下TimeInterpolator的源码。

frameworks/base/core/java/android/animation/TimeInterpolator.java的源码如下:

/** * A time interpolator defines the rate of change of an animation. This allows animations * to have non-linear motion, such as acceleration and deceleration. */public interface TimeInterpolator {    /**     * Maps a value representing the elapsed fraction of an animation to a value that represents     * the interpolated fraction. This interpolated value is then multiplied by the change in     * value of an animation to derive the animated value at the current elapsed animation time.     *     * @param input A value between 0 and 1.0 indicating our current point     *        in the animation where 0 represents the start and 1.0 represents     *        the end     * @return The interpolation value. This value can be more than 1.0 for     *         interpolators which overshoot their targets, or less than 0 for     *         interpolators that undershoot their targets.     */    float getInterpolation(float input);}

TimeInterpolator定义了动画变化的接口。float getInterpolation(float input)的输入是[0, 1.0],是动画插值器的归一化时间,0表示开始,1.0表示结束。返回值是动画插值器的归一化结果[0, 1.0],但是,返回值在超越目标(overshoot their targets)的时候,也可以<0或者>1.0。

更多相关文章

  1. 分享20个Android游戏源码,希望大家喜欢哈!
  2. 补间动画
  3. android 常用api 接口签名验证
  4. Android 海贼王连连看游戏源码
  5. 在服务器上使用 gradle 打包 android 源码
  6. android 关于图片的放大,缩小,旋转功能的实现(附源码)
  7. 将ffmpeg编译到android 源码
  8. [置顶] Android学习进阶路线导航线路(Android源码分享)
  9. android音乐播放器源案例源码

随机推荐

  1. Android】获取Mac地址
  2. AndroidStudio 使用技巧:无法删除 Androi
  3. Android之十一实现登陆页面分析
  4. android编码问题
  5. Ubuntu 配置 Android 开发 环境
  6. Android加载/处理超大图片神器!
  7. Android XML文件 Error parsing XML: unb
  8. ReactNative 调用Android 原生(二)——原生
  9. android相机预览
  10. Android学习_android镜像