Android属性动画实战教程中篇

本来预计本系列博客只有俩篇,但是考虑到后面的知识点比较重要,所以拆开为俩篇博客来介绍,一篇理论和一篇例子。
有想直接了解用法,用到项目中,可以看上一篇博客Android属性动画实战教程开篇

下面开始本篇博客的内容。本篇博客主要是介绍插值器(TimeInterpolator)估值器(TypeEvaluator)

根据参考 郭霖属性动画的系列博客 还有配合 任玉刚-Android艺术开发探索-Android动画深入分析 决定先介绍估值器(TypeEvaluator)

首先看一下Android源码关于TypeEvaluator

public interface TypeEvaluator<T> {

    /**
     * This function returns the result of linearly interpolating the start and end values, with
     * <code>fraction</code> representing the proportion between the start and end values. The
     * calculation is a simple parametric calculation: <code>result = x0 + t * (x1 - x0)</code>,
     * where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>,
     * and <code>t</code> is <code>fraction</code>.
     *
     * @param fraction   The fraction from the starting to the ending values
     * @param startValue The start value.
     * @param endValue   The end value.
     * @return A linear interpolation between the start and end values, given the
     *         <code>fraction</code> parameter.
     */
    public T evaluate(float fraction, T startValue, T endValue);

}
TypeEvaluator 是一个接口,只有一个方法 evaluate 关于他的三个参数
第一个参数很重要表示 从开始到结束当前动画的完成度
第二个参数是 起始值
第三个参数是 结束值

返回一个在开始值和结束值之间值

除了了可以使用Android内部已经实现好的估值器,我们也可以指定,只要实现该接口即可。

看到这里,也许会有好多人还有疑问。就是fraction这个参数是是在那进行实例化的。

这个时候就需要介绍插值器(TimeInterpolator)

首先先看一下Android源码关于TimeInterpolator

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 是一个接口,只有一个方法 getInterpolation关于他的唯一个参数
是一个0.0-1.0之间的值表示当前时间流逝百分比

返回一个属性值改变的百分比0.0-1.0

除了使用Android内部提供我们的插值器,我们也可以自定义插值器,根据自己的具体需求,通过参数input时间流逝百分比进行计算动画属性改变的百分比并返回。

根据 插值器估值器 之间的关系配合 ValueAnimator 已经我们的需求,我们就可以定义出任意的动画。
ValueAnimator 这个我们在上篇博客提过,他主要是对值做了动画,并没有作用对象和动画效果

本篇博客介绍到这里,主要是理论方面的内容,重在理解。下篇博客会介绍一个综合的例子,加深理解。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值