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();
}
}
Posted byAlan
既然生,就生如夏花之绚烂;淡然死,却死若秋叶之静美!