最近在做一下项目,是领取红包的,我们这里仿照的微信的红包领取界面,点击按钮之后立体旋转,然后打开红包:
我这里用的是旋转动画,然后沿着Y轴去旋转,说了这么多,下面来看一下效果:

现在清楚多了把 ,我用自定义了一个动画,找到控件的中心,然后让中心沿着Y轴去旋转,不多说了看代码吧:
package com.lixuce.myapplication;
import android.content.Context;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Transformation;
/**
* Created by lixuce on 2017/4/10.
*/
public class MyAnimation extends Animation {
int centerX, centerY;
Camera camera = new Camera();
@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(2500L);
setInterpolator(new AccelerateInterpolator());
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final Matrix matrix = t.getMatrix();
camera.save();
//中心是绕Y轴旋转 这里可以自行设置X轴 Y轴 Z轴
camera.rotateY(1080 * interpolatedTime);
//把我们的摄像头加在变换矩阵上
camera.getMatrix(matrix);
//设置翻转中心点
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
camera.restore();
}
}
用法:
MyAnimation mAnimation = new MyAnimation();
ivxuanzhuan.startAnimation(mAnimation); 这样是不是很容易就实现了动画了效果了。希望能对大家有所帮助
|