android:开发,animation动画操作类的一个练习

package com.lanxin.testanim;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;

import java.util.Locale;

/**
 * Created by Administrator on 2016/6/15 0015.
 */
public class ViewAnim extends Animation {

    private static final String TAG = "ViewAnimLog";
    private float centerX,centerY;
    private Camera camera = new Camera();

    public ViewAnim(float cx,float cy){
        centerX = cx;
        centerY = cy;
        Log.i(TAG,"ViewAnim");

    }

    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        //centerX = width / 2.0f;
        //centerY = height / 2.0f;

        setDuration(2500);
        setFillAfter(true);
        setInterpolator(new LinearInterpolator());
    }

    protected void applyTransformation(float interpolatedTime, Transformation t) {
        Matrix matrix = t.getMatrix();
        //matrix.setScale(interpolatedTime,interpolatedTime);
        matrix.setRotate(360.0f * interpolatedTime);
        matrix.preTranslate(-centerX, -centerY);
        matrix.postTranslate(centerX,centerY);
        //applyTransformation2(interpolatedTime,t);
        Log.i(TAG,""+interpolatedTime);
    }

    protected void applyTransformation2(float interpolatedTime, Transformation t) {
        Matrix matrix = t.getMatrix();

        camera.save();
        camera.translate(0.0f, 0.0f, (1300.0f - 1300.0f * interpolatedTime));
        camera.rotateY(360.0f * interpolatedTime);
        camera.getMatrix(matrix);

        matrix.preTranslate(-centerX,-centerY);
        matrix.postTranslate(centerX,centerY);
        camera.restore();
    }
}

Leave a Comment

 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |