Android Notes 之 Tween动画 (2)自定义动画

自定义动画需要继承Animation类,这个类主要的要实现的方法是
applyTransformation,在整个动画期间这个函数会一直被调用,interpolatedTime取值从0到1。

/** * Created by tongs on 2016/4/13. * email:[email protected] */
public class My_Anim extends Animation {

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);
        //设置移动动画,根据sin函数来进行周期运动
        t.getMatrix().setTranslate((float) Math.sin(interpolatedTime*20)*70,0);
    }
}

运行效果:
Android Notes 之 Tween动画 (2)自定义动画_第1张图片

你可能感兴趣的:(动画,android)