我们先看看苹果的一个摆动效果,就两个字酷炫。
所以安卓能搞吗,答案是肯定的啦
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
//Z轴画圆动画
public class ZAxisCirclingAnimation extends Animation {
int centerX, centerY;
Camera camera = new Camera();
float range = 9f;
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
//获取中心点坐标
centerX = width / 2;
centerY = height / 2;
//动画执行时间 自行定义
setDuration(4000);
setInterpolator(new LinearInterpolator());
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final Matrix matrix = t.getMatrix();
camera.save();
//放大时间
float timeAmplifier;
if (0 <= interpolatedTime && interpolatedTime <= 0.25f) {
timeAmplifier = 4f * interpolatedTime;
camera.rotateX( (float)Math.toDegrees(Math.asin((1f-timeAmplifier)/range)));
camera.rotateY( (float)Math.toDegrees(Math.asin(timeAmplifier/range)));
} else if (0.25f < interpolatedTime && interpolatedTime <= 0.5f) {
timeAmplifier = 4f * (interpolatedTime-0.25f);
camera.rotateX( -((float)Math.toDegrees(Math.asin(timeAmplifier/range))));
camera.rotateY( (float)Math.toDegrees(Math.asin((1f-timeAmplifier)/range)));
} else if (0.5f < interpolatedTime && interpolatedTime <= 0.75f) {
timeAmplifier = 4f * (interpolatedTime-0.5f);
camera.rotateX( -((float)Math.toDegrees(Math.asin((1f-timeAmplifier)/range))));
camera.rotateY( -((float)Math.toDegrees(Math.asin(timeAmplifier/range))));
} else if (0.75f < interpolatedTime && interpolatedTime <= 1) {
timeAmplifier = 4f * (interpolatedTime-0.75f);
camera.rotateX( (float)Math.toDegrees(Math.asin(timeAmplifier/range)));
camera.rotateY( -((float)Math.toDegrees(Math.asin((1f-timeAmplifier)/range))));
}
//把我们的摄像头加在变换矩阵上
camera.getMatrix(matrix);
//设置翻转中心点
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
camera.restore();
}
}
达到的效果:
额,怎么感觉很像有点不同呢.........
问题不大好吗 它的动作要领在线就行
---分割线---
------2018-03-29------最终效果实现。
备注:使用此动画的View记得开抗锯齿。
有一点要注意下,就是用阴影来对抗锯齿。这个旋转动画的锯齿太严重了, view做了抗锯齿也很严重。我突发奇想,锯齿的来源是绘制运动的直线导致的。我们让它边缘是很多的点那不就解决了。