1 public class Rotate3dAnimation extends Animation {      // 开始角度
 2     private final float mFromDegrees;      // 结束角度
 3     private final float mToDegrees;      // 旋转的x坐标
 4     private final float mCenterX;      // 旋转的y坐标
 5     private final float mCenterY;      // 旋转的z坐标
 6     private final float mDepthZ;      // 是否扭曲
 7     private final boolean mReverse;
 8     private Camera mCamera;
 9
10     /**
11      * Creates a new 3D rotation on the Y axis. The rotation is defined by its
12      * start angle and its end angle. Both angles are in degrees. The rotation
13      * is performed around a center point on the 2D space, definied by a pair
14      * of X and Y coordinates, called centerX and centerY. When the animation
15      * starts, a translation on the Z axis (depth) is performed. The length
16      * of the translation can be specified, as well as whether the translation
17      * should be reversed in time.
18      *
19      * @param fromDegrees the start angle of the 3D rotation
20      * @param toDegrees the end angle of the 3D rotation
21      * @param centerX the X center of the 3D rotation
22      * @param centerY the Y center of the 3D rotation
23      * @param reverse true if the translation should be reversed, false otherwise
24      */
25     public Rotate3dAnimation(float fromDegrees, float toDegrees,
26             float centerX, float centerY, float depthZ, boolean reverse) {
27         mFromDegrees = fromDegrees;    
28         mToDegrees = toDegrees;
29         mCenterX = centerX;
30         mCenterY = centerY;
31         mDepthZ = depthZ;
32         mReverse = reverse;
33     }
34
35     @Override
36     public void initialize(int width, int height, int parentWidth, int parentHeight) {
37         super.initialize(width, height, parentWidth, parentHeight);
38         mCamera = new Camera();
39     }
40
41     @Override
42     protected void applyTransformation(float interpolatedTime, Transformation t) {
43         final float fromDegrees = mFromDegrees;
44         float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
45
46         final float centerX = mCenterX;
47         final float centerY = mCenterY;
48         final Camera camera = mCamera;
49
50         final Matrix matrix = t.getMatrix();
51
52         camera.save();
53         if (mReverse) {
54             camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
55         } else {
56             camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
57         }
58         camera.rotateY(degrees);
59         camera.getMatrix(matrix);
60         camera.restore();
61
62         matrix.preTranslate(-centerX, -centerY);
63         matrix.postTranslate(centerX, centerY);
64     }
65 }  

调用:

 1  img = (ImageView) view.findViewById(R.id.img);
 2         img.setOnClickListener(new View.OnClickListener() {
 3             @Override
 4             public void onClick(View v) {
 5                 if (!isFront){
 6                     applyRotation(0, 180);
 7                     isFront = true;
 8                 }else {
 9                     applyRotation(180, 360);
10                     isFront = false;
11                 }
12             }
13         });
14
15  private void applyRotation(float start, float end) {
16         // 计算中心点
17         final float centerX = img.getWidth() / 2.0f;
18         final float centerY = img.getHeight() / 2.0f;
19         final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end,
20                 centerX, centerY, 0f, true);
21         rotation.setDuration(1000);
22         rotation.setFillAfter(true);
23         rotation.setInterpolator(new AccelerateInterpolator());
24         // 设置监听
25         rotation.setAnimationListener(new DisplayNextView());
26         img.startAnimation(rotation);
27         test.startAnimation(rotation);
28         test.postDelayed(new Runnable() {
29             @Override
30             public void run() {
31                 if (isFront){
32                     test.setText("我是大帝");
33                 }else{
34                     test.setText("世界你好");
35                 }
36             }
37         },700);
38     }
39     private final class DisplayNextView implements Animation.AnimationListener {
40         public void onAnimationStart(Animation animation) {
41         }
42         // 动画结束
43         public void onAnimationEnd(Animation animation) {
44
45         }
46
47         public void onAnimationRepeat(Animation animation) {
48         }
49     }

转载于:https://www.cnblogs.com/blkspm/p/5217102.html

Android 3D 旋转相关推荐

  1. Android 3D旋转动画库

    今天兴趣来潮,撸了一个动画特效,我把他应用在登录的界面,当然也可以用在其他地方,先来预览一下我的特效吧 使用方法 1. 在build.gradle里面配置如下 dependencies {compil ...

  2. Android做3D旋转动画,Android编程实现3D旋转效果实例

    本文实例讲述了Android编程实现3D旋转效果的方法.分享给大家供大家参考,具体如下: 下面的示例是在Android中实现图片3D旋转的效果. 实现3D效果一般使用OpenGL,但在Android平 ...

  3. 进阶六之Android UI介面之(介面3D旋转)

    天道酬勤.也许你付出了不一定得到回报,但不付出一定得不到回报. 本讲内容:介面3D旋转 示例一效果图:                 下面是res/layout/activity_main.xml ...

  4. android 卡片旋转动画,Android 卡片翻转效果

    Android 卡片翻转效果使用的Cramre来完成 记录一下: 一个好用的3D旋转工具类 oid.graphics.Matrix; import android.util.Log; import a ...

  5. android 人物行走动画,android 3D 游戏实现之人物行走(MD2)

    如果充分理解了HelloWorld(见android 3D 游戏实现之First step),了解了一些JPCT-AE游戏框架的机制, 那么,这个示例可以是进阶篇了,其实用JPCT-AE加载3DS,M ...

  6. Android 3D滑动菜单完全解析,实现推拉门式的立体特效

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/10471245 在上一篇文章中,我们学习了Camera的基本用法,并借助它们编写了一 ...

  7. Android 3D 魔方游戏的设计与开发

    Android 3D 魔方游戏的设计与开发 5.1 Feature 定义 魔方是一个有趣的益智游戏,相信很多人都玩过.本次毕业设计,欲完成的主要的功能如下: (1) 开始游戏:开始一个新的游戏 (2) ...

  8. android飞行射击游戏代码,android 3D飞行射击游戏《夜鹰行动》源码

    压缩包内容概览: android 3D飞行射击游戏<夜鹰行动>源码-airattacker ; 清单 ; 资产 ; 项目 ; 飞骥11 ; 飞骥22 ; 飞骥33 ; 折叠按钮 ; 弗雷格 ...

  9. 【备注】【C24】《Android 3D游戏开发技术详解与典型案例》PDF 下载

    [C24]<Android 3D游戏开发技术详解与典型案例>PDF 下载 目前市面上的Android技术书籍还比较少,Android3D游戏开发的书籍更是没有.因此,在现在市面上,Andr ...

  10. Android+3D游戏开发技术详解与典型案例

    内容导读 本书共分两篇,第一篇介绍了Android 3D游戏开发的基础知识,主要对OpenGL ES的相关内容进行了介绍. 章 名主 要 内 容 第1章 英雄还看今朝-Android简介本章介绍了市场 ...

最新文章

  1. Entity framewrok (linq to entity)查询优化的一点摸索
  2. maven book
  3. springboot创建多个对象
  4. c 编程 mysql结果集_使用mysql C语言API编写程序—MYSQL数据库查询操作(执行查询操作,获取查询结果的字段数,记录行数,...
  5. 谷歌cloud_通过使用Google Cloud ML大规模提供机器学习模型,我们学到了什么
  6. 学习node.js的一些笔记
  7. JSLIU 的 wxWindows 入门
  8. jdk11 及jdk8阿里云快速下载链接
  9. Jetson Nano 入坑之路 ----(9)C++调用SYN6288语音播报模块
  10. 三诺 n20g 微型计算机,就是要更完美 三诺N-20GIII提升巨大
  11. Windows+chrome中关闭自动更新
  12. 采用MCaaS模式 SAP为有孚网络提供基于HANA的解决方案及服务
  13. mysql 手动写时间_MySQL如何在范围内填写缺失日期?
  14. 电脑怎么图片转文字?建议收藏这几个方法
  15. 游戏画质修改器GFX工具箱(GFX tool)_9.9.8特别版
  16. bcmsh交换芯片调试接口
  17. asp.net zero 8.2 学习-12- abp 文件上传、获取、删除
  18. mac pdf去水印_PDF水印工具Mac版
  19. scrapy爬取斗鱼图片并且重命名后保存
  20. 子域名扫描工具-Sublist3r

热门文章

  1. 学习笔记(16):程序员的数学:微积分-常用导数(一):最常用到的技巧
  2. Excel中的单元格引用
  3. 跑马灯的一些使用心得
  4. 英语入门学习笔记2:英语语法知识树
  5. 分享抖音上热门技巧!短视频涨粉+运营攻略!
  6. 亚马逊中国发布2015图书排行榜
  7. android多开器工作原理,[原创]app隐藏大师绕过密码与多开分析
  8. php制作水印图片,PHP实例制作水印图片
  9. VOA special English 下载 py
  10. 区块链技术实体结合解决方案——汇新云