android 动画 插值器和估值器

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);
        }
    }

4. ValueAnimator.ofObject()的本质还是操作值, 只是将 多个值 封装到一个对象里,同时对 该对象 里的 多个值 一起操作而已

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值