1. 插值器(TimeInterpolator)
1. 时间百分比===》属性百分比===》属性值。
2. 主要方法getInterpolation
3. getInterpolation参数和返回值说明
input:
当前动画用的时间/动画总时间 动画时间为1000 动画到400的时候 传入的input==400/1000
返回值:
属性值变化的百分比 start(0),end(100) 如果是匀速的话,返回的值应该为 属性值变化比和时间比是一样的。 如果返回值大于了input就是加速了,小于就是减速了。
通俗点讲就是,时间用了1/3 属性值变化了2/3 就是变化的快了,就是加速了。 时间用了2/3,属性值变化了1/3 就是减速了。
/** * An abstract class which is extended by default interpolators. */ abstract public class BaseInterpolator implements Interpolator { private @Config int mChangingConfiguration; /** * @hide */ public @Config int getChangingConfiguration() { return mChangingConfiguration; } /** * @hide */ void setChangingConfiguration(@Config int changingConfiguration) { mChangingConfiguration = changingConfiguration; } }
/** * An interpolator where the rate of change is constant */ @HasNativeInterpolator public class LinearInterpolator extends BaseInterpolator implements NativeInterpolatorFactory { public LinearInterpolator() { } public LinearInterpolator(Context context, AttributeSet attrs) { } public float getInterpolation(float input) { return input; } /** @hide */ @Override public long createNativeInterpolator() { return NativeInterpolatorFactoryHelper.createLinearInterpolator(); } }
2. 估值器(TypeEvaluator)
1. 主要方法evaluate
2. 参数说明和返回值
fraction:插值器返回值
startValue:开始的属性值
endValue:结束的属性值
返回值:通过计算后的属性值,最后通过addUpdateListener 调用ValueAnimator的getAnimatedValue方法获取属性值作用于object
public interface TypeEvaluator<T> { public T evaluate(float fraction, T startValue, T endValue); }
public class FloatEvaluator implements TypeEvaluator<Number> { public Float evaluate(float fraction, Number startValue, Number endValue) { float startFloat = startValue.floatValue(); return startFloat + fraction * (endValue.floatValue() - startFloat); } }
public class ValueAnimator extends Animator implements AnimationHandler.AnimationFrameCallback { public static interface AnimatorUpdateListener { /** * <p>Notifies the occurrence of another frame of the animation.</p> * * @param animation The animation which was repeated. */ void onAnimationUpdate(ValueAnimator animation); } }
3. 默认插值器和估值器
//ValueAnimator.class @Override public void setInterpolator(TimeInterpolator value) { if (value != null) { mInterpolator = value; } else { mInterpolator = new LinearInterpolator(); } } //PropertyValuesHolder.class void init() { if (mEvaluator == null) { // We already handle int and float automatically, but not their Object // equivalents mEvaluator = (mValueType == Integer.class) ? sIntEvaluator : (mValueType == Float.class) ? sFloatEvaluator : null; } if (mEvaluator != null) { // KeyframeSet knows how to evaluate the common types - only give it a custom // evaluator if one has been set on this class mKeyframes.setEvaluator(mEvaluator); } }