跳至主要内容

博文

目前显示的是标签为“interpolator”的博文

Android 四种特殊Interpolator源码解析 收藏

animation.setInterpolator(new BounceInterpolator()); 今天介绍4种动画插值器 OvershootInterpolator: "Overshoot" means 冲过头了,模拟了冲过了头回滚一点的效果 AnticipateInterpolator:“Anticipate” means 抢先,模拟了出发前先后退一步再前冲的动画效果 AnticipateOvershootInterpolator:以上两种的结合 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 = 3 t^ 3 + 2 t^ 2 + 1 // t:[- 1 ~ 0 ] 然后去google搜索一下"3t^3+2t^2+1",就能看到下面这个曲线图 我们改下参数mTension,就能发现 mTension越大,冲过的距离越大,效果越明显! AnticipateInterpolation 再看下Anticipate的实现数学公式,mTension同样默认是2.0f: public float getInterpolation ( float t) { return t * t * ((mTension + 1 ) * t - mTension); } 于是带上实际参数2.0f,得到 y = 3 t^ 3 - 2 t^ 2 //t:[ 0 ~ 1.0 ] 同样的结论: mTension越大,抢先动画约长,效果越明显! BounceInterpolator 从源码我们能发现,实现方式是根据时间t,模拟了一次...

android animation中的参数interpolator详解

anim.setInterpolator(new AccelerateInterpolator()); XML:interpolator ="@android:anim/accelerate_interpolator" Android :interpolator     interpolator 被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果可以 accelerated(加速),decelerated(减速),repeated(重复),bounced(弹跳)等。   android 自带的interpolator       AccelerateDecelerateInterpolator 在动画开始与介绍的地方速率改变比较慢,在中间的时候加速      AccelerateInterpolator  在动画开始的地方速率改变比较慢,然后开始加速    AnticipateInterpolator 开始的时候向后然后向前甩    AnticipateOvershootInterpolator 开始的时候向后然后向前甩一定值后返回最后的值    BounceInterpolator   动画结束的时候弹起    CycleInterpolator 动画循环播放特定的次数,速率改变沿着正弦曲线    DecelerateInterpolator 在动画开始的地方快然后慢      LinearInterpolator   以常量速率改变      OvershootInterpolator    向前甩一定值后再回到原来位置