android 翻转效果动画源码
2014-10-20 19:40
405 查看
最近项目上要求做一个翻转的动画效果,由于动画还没有怎么使用过。然后再网上找到一份很实用的翻转动画先用起来,以后再学习下动画相关的。
源码修改后如下:
public class FlipAnimator extends Animation {
private Camera camera;
private float centerX;
private float centerY;
public FlipAnimator() {
setFillAfter(true);
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
camera = new Camera();
this.centerX = width / 2;
this.centerY = height / 2;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
// Angle around the y-axis of the rotation at the given time. It is
// calculated both in radians and in the equivalent degrees.
final double radians = Math.PI * interpolatedTime;
float degrees = (float) (180.0 * radians / Math.PI);
degrees = -degrees;
// Once we reach the midpoint in the animation, we need to hide the
// source view and show the destination view. We also need to change
// the angle by 180 degrees so that the destination does not come in
// flipped around. This is the main problem with SDK sample, it does not
// do this.
if (interpolatedTime >= 0.5f) {
degrees += 180.f;
}
final Matrix matrix = t.getMatrix();
camera.save();
camera.translate(0.0f, 0.0f, (float) (150.0 * Math.sin(radians)));
// camera.rotateX(degrees);
camera.rotateY(degrees);
// camera.rotateZ(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
动画通过Camera 和Matrix实现。文中注视的部分camera.rotateX(degrees)和camera.rotateZ(degrees)分别为X和Z轴的旋转,没有用到故先注释。
使用方法很简单
FlipAnimator flipAnimator = new FlipAnimator();
flipAnimator.setDuration(200);
startAnimation(flipAnimator);
源码修改后如下:
public class FlipAnimator extends Animation {
private Camera camera;
private float centerX;
private float centerY;
public FlipAnimator() {
setFillAfter(true);
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
camera = new Camera();
this.centerX = width / 2;
this.centerY = height / 2;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
// Angle around the y-axis of the rotation at the given time. It is
// calculated both in radians and in the equivalent degrees.
final double radians = Math.PI * interpolatedTime;
float degrees = (float) (180.0 * radians / Math.PI);
degrees = -degrees;
// Once we reach the midpoint in the animation, we need to hide the
// source view and show the destination view. We also need to change
// the angle by 180 degrees so that the destination does not come in
// flipped around. This is the main problem with SDK sample, it does not
// do this.
if (interpolatedTime >= 0.5f) {
degrees += 180.f;
}
final Matrix matrix = t.getMatrix();
camera.save();
camera.translate(0.0f, 0.0f, (float) (150.0 * Math.sin(radians)));
// camera.rotateX(degrees);
camera.rotateY(degrees);
// camera.rotateZ(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
动画通过Camera 和Matrix实现。文中注视的部分camera.rotateX(degrees)和camera.rotateZ(degrees)分别为X和Z轴的旋转,没有用到故先注释。
使用方法很简单
FlipAnimator flipAnimator = new FlipAnimator();
flipAnimator.setDuration(200);
startAnimation(flipAnimator);
相关文章推荐
- Android 动画分析之翻转效果
- Android动画分析之3D翻转效果
- Android BaseAnimation近200种动画效果源码
- Android/OPhone动画分析之翻转效果
- Android UI效果篇-(2)炫酷动画源码
- Android动画分析之3D翻转效果
- Android应用系列:仿MIUI的Toast动画效果实现(有图有源码)
- Android补间动画效果translate、scale、alpha、rotate详解(带源码)XML实现
- Android页面翻转动画(模仿CSDN账号登录的翻转效果)
- Android源码集锦,悬浮窗综合资讯类APP动画效果左右切换效果美妆领域
- Android动画分析之3D翻转效果
- Android实现Flip翻转动画效果
- 实例源码--Android自定义Gallery动画效果
- Android卡牌翻转动画效果实现
- Android\OPhone动画分析之翻转效果
- Android动画之3D翻转效果实现函数分析
- Android\OPhone动画分析之翻转效果 推荐
- Android动画分析之3D翻转效果
- Android 卡片翻转动画效果
- Android实现文字翻转动画的效果