做了些动画,发现动画都有一个Interpolator的属性,它到底是个啥东西?
网上也有很多解释Interpolator的文章,基本上都是停留在直接翻译SDK的意思层面上。看了,也就明白一个大概。
Interpolator英文意思是: 篡改者; 分类机; 校对机
SDK对Interpolator的描述是: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。简而言之Interpolator就是一个“变化率”,一个基本动画的“变化率”。
比如:从A到B的一个平移动画,移动,当然后速度的快慢,那么从A到B可以是匀速、匀加速、匀减速、变速完成这段距离。假设距离为S,时间为t,速度为v,都知道S=v*t。
这个Interpolator在这里就是一个速度控制器,控制速度变化。先给一个对Interpolator的大概理解,接下来站在程序员的角度来认识Interpolator。
Interpolator借口只有一个抽象方法getInterpolation(float input),由此SDK中扩展了另外几个常用Interpolator类,分别是:
——AccelerateInterpolator:动画从开始到结束,变化率是一个加速的过程。
——DecelerateInterpolator:动画从开始到结束,变化率是一个减速的过程。
——CycleInterpolator:动画从开始到结束,变化率是循环给定次数的正弦曲线。
——AccelerateDecelerateInterpolator:动画从开始到结束,变化率是先加速后减速的过程。
——LinearInterpolator:动画从开始到结束,变化率是线性变化。
..............
这里给一个简单的实现Interpolator接口的类:
import android.view.animation.Interpolator;
public class MyInterpolator implements Interpolator {
private float mFactor;
private int i;
public MyInterpolator(int i){
this.i = i;
}
@Override
public float getInterpolation(float input) {
switch(i){
case 1:mFactor = input;
break;
case 2:mFactor = input*input*input;
break;
}
return mFactor;
}
}
当初始变量为1的时候,mFactor = input,是一个线性函数,“变化率”是匀速的
当初始变量为2的时候,mFactor = input*input*input,是一个曲线函数,“变化率”呈三次方。
这里需要注意的是,input是一个0.0f~1.0f的浮点类型
从上面看来,自定义一个Interpolator就是用input根据所需构造一个函数出来
比如:这里把初始变量为2的时候,把函数改为:mFactor=3*input。这里给出一个测试出来的效果图
这两个图所做的动画都是往下移动100的距离,时间都为3000ms.并且同时做。那为什么绿色的花移动距离是紫色花移动距离的3倍呢?这里来分析一下。
都是以input为变量的一次线性函数,故两者都是匀速运动,此时后者的速度是前者的3倍,所以移动距离也应该是3被。回过头来看,在设置TranslateAniamtion的时候,明明是移动一样的距离啊!这里可以猜测这时设置的距离就不起效果了,也就是Interpolator改变了之前设置的距离。
现在基本上明白了Interpolator到底是做什么的了!
不说了,玩Dota了
分享到:
相关推荐
Android 动画Interpolator和 button自定义涟漪效果和百分比布局
android动画插值器Interpolator使用demo 博客 http://blog.csdn.net/wingichoy/article/details/50667025
androidx-interpolator-1.0.0.aar
android Interpolator的使用
interpolator
利用interpolator和AnimationSet来实现抛物线动画.
Interpolator (插值器)被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果accelerated(加速),decelerated(减速),repeated(重复),bounced(弹跳)等。 详细说明:...
本示例是一个Android应用程序。通过自定义View实现动画效果,同时可以利用系统提供的加速器Interpolator控制动画的变化速度。
想要了解内容的请看这篇博客:http://blog.csdn.net/rookielog/article/details/50551341
博客《 Animation动画详解(二)——Interpolator插值器》对应源码,博客地址:http://blog.csdn.net/harvic880925/article/details/40049763
本文实例讲述了Android编程实现RotateAnimation设置中心点旋转动画效果。分享给大家供大家参考,具体如下: 在xml设置: <?xml version=1.0 encoding=utf-8?... android:interpolator=@android:anim/linear
android 动画的插值器
此示例演示了如何使用插值动画和路径动画材质设计。它显示了如何将ObjectAnimator用于动态视图的两个属性(缩放X和Y)沿着一条路径。
针对Android补间动画属性中的Interpolator,写了基本例子测试一下android提供给我们现成的加速器的效果
InterpolatorShow A apk to show interpolator.and you can add customize interpolator too. Developed By chen lin phenix_chen@126.com
Interpolator动画demo,针对Interpolator的几种标签:translate标签,rotate标签,alpha标签,scale标签
interpolator指定动画插入器,常见的有加速减速插入器accelerate_decelerate_interpolator,加速插入器accelerate_interpolator,减速插入器decelerate_interpolator。 fromXScale,fromYScale,动画开始前X,Y的缩放...
interpolator:动画插入器(加速、减速插入器) repeatCount:动画重复的次数 repeatMode:顺序动画(restart)/倒序动画(reverse) startOffset:动画之间时间间隔 对于动画的创建一般有两种方式: 第一种是在...
Boosted Android Tab Layout with custom animated indicators including "Dachshund" animation inspired by this. Sample Available Animated Indicators Indicator Example Custom behavior ...
Interpolator用于动画中的时间插值,其作用就是把0到1的浮点值变化映射到另一个浮点值变化