android 翻转效果动画源码
来源:互联网 发布:数据库增删改查 编辑:程序博客网 时间:2024/05/18 00:56
最近项目上要求做一个翻转的动画效果,由于动画还没有怎么使用过。然后再网上找到一份很实用的翻转动画先用起来,以后再学习下动画相关的。
源码修改后如下:
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);
0 0
- android 翻转效果动画源码
- Android图片翻转动画效果
- Android 翻转动画 Rotate3dAnimation 效果
- Android 卡片翻转动画效果
- Android/OPhone动画分析之翻转效果
- Android\OPhone动画分析之翻转效果
- Android 动画分析之翻转效果
- 简单实现Android图片翻转动画效果
- Android---显示卡片翻转的动画效果
- Android卡牌翻转动画效果实现
- 文字翻转动画效果
- 制作翻转效果动画
- Android3D动画翻转效果
- 硬币翻转动画效果
- Card翻转动画效果
- 翻转动画效果
- 动画翻转效果
- Android动画分析之翻转效果(camera、gallery)
- vijosp1202 Selection
- java.lang.OutOfMemoryError: Java heap space解决方法,绝对管用
- 终端中 多标签切换快捷键
- javascript中"return obj === void 0"这种写法的原因和好处
- mongodb常用维护命令汇总
- android 翻转效果动画源码
- POJ 2375 Cow Ski Area(强连通)
- ARM--交叉编译器及开发板系统的安装
- Redis 3.0官方文档翻译计划(2)——数据类型初探
- java自带线程池和队列详细讲解
- lua的 math库
- Lua弱表Weak table
- opencv 基本包
- 阻塞IO的理解