canvas & animation

1.using canvas

using canvas to set difference property. it will showing like an animation.

The true animation is also showing using this.

2.AnimatorUpdateListener

关键点是,在动画注册以后,可以监听AnimatorUpdateListener,然后通过:

    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        invalidate();// Important,
    }

通过这个方法,可以自动刷新onDraw,而不用判断时间以及属性变化。

在动画的变换过程中,

        Anim = ObjectAnimator.ofFloat(mDrawImage, "y", 0,
                mDrawImage.getHeight()).setDuration(200);
ofFloat后面是object,也就是变换的object的“y”属性,所以可以变换任意object的public属性。
而y属性会按照给定的方式:
Anim.setInterpolator(new LinearInterpolator());
LinearInterpolator可以替换为android定义的各种变换方式,或者是自定义的方式。

自此,每次在onAnimationUpdate相应的时候,可以看到,Y按照动画的变换规律进行的变化。
而canvas draw的时候,运用到该属性,就可以实现动画的效果。




原文地址:https://www.cnblogs.com/deman/p/4372469.html