自定义动画

来源:互联网 发布:中国护理质量数据平台 编辑:程序博客网 时间:2024/06/16 02:30

创建自定义动画

1、覆盖父类的initialize方法,实现初始化工作。

2、实现applyTransformation的逻辑。

 @Override    protected void applyTransformation(float interpolatedTime, Transformation t) {        super.applyTransformation(interpolatedTime, t);    }

第一个参数:差值器时间因子,范围0-1.0。

第二个参数:矩阵的封装类。可以用来获得当前的矩阵对象,通过改版matrix来实现效果的动画。

 final Matrix matrix = t.getMatrix();

模拟电视开机

public class MyAnimation extends Animation {    private int mCenterX;    private int mCenterY;    private Camera camera = new Camera();    @Override    public void initialize(int width, int height, int parentWidth, int parentHeight) {        super.initialize(width, height, parentWidth, parentHeight);        setDuration(500);        setFillAfter(true);        setInterpolator(new LinearInterpolator());        mCenterX = width / 2;        mCenterY = height / 2;    }    @Override    protected void applyTransformation(float interpolatedTime, Transformation t) {        super.applyTransformation(interpolatedTime, t);        final Matrix matrix = t.getMatrix();        camera.save();        if (interpolatedTime < 0.8) {            matrix.preScale(1 + 0.625f * interpolatedTime, 1 - interpolatedTime / 0.8f + 0.01f, mCenterX, mCenterY);        } else {            matrix.preScale(7.5f * (1 - interpolatedTime), 0.01f, mCenterX, mCenterY);        }        camera.restore();    }}

1 0
原创粉丝点击