android 实现3d旋转
Android  /  houtizong 发布于 3年前   138
通过继承Animation动画类 封装了一个3d旋转的效果代码如下
import android.graphics.Camera;import android.graphics.Matrix;import android.view.animation.Animation;import android.view.animation.Transformation;public class Rotatw3d extends Animation{private float mFromDegree;private float mToDegree;private float mCenterX;private float mcenterY;private float mleft;private float mTop;private Camera mCamera;private static final String TAG="Rotate3d";public Rotatw3d(float mFromDegree, float mToDegree, float mCenterX,float mcenterY, float mleft, float mTop){this.mFromDegree = mFromDegree;this.mToDegree = mToDegree;this.mCenterX = mCenterX;this.mcenterY = mcenterY;this.mleft = mleft;this.mTop = mTop;}@Overridepublic void initialize(int width, int height, int parentWidth,int parentHeight){super.initialize(width, height, parentWidth, parentHeight);mCamera=new Camera();}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t){final float FromDegree =mFromDegree;float degrees=FromDegree+(mToDegree-mFromDegree)*interpolatedTime;final float centerX=mCenterX;final float centerY=mcenterY;final Matrix matrix=t.getMatrix();if(degrees<=-76.0f){degrees=-90.0f;mCamera.save();mCamera.rotateY(degrees);mCamera.getMatrix(matrix);mCamera.restore();}else if(degrees>=76.0f){degrees=90.0f;mCamera.save();mCamera.rotateY(degrees);mCamera.getMatrix(matrix);mCamera.restore();}else {mCamera.save();mCamera.translate(0, 0, centerX);mCamera.rotateY(degrees);mCamera.translate(0, 0, -centerX);mCamera.getMatrix(matrix);mCamera.restore();}matrix.preTranslate(-centerX, -centerX);matrix.postTranslate(centerX, centerX);}}
简单的调用
Rotatw3d leftaction=new Rotatw3d(-0, -90, -100, -100, -100, -100); leftaction.setFillAfter(true); leftaction.setDuration(5000); ImageView image=(ImageView)findViewById(R.id.image); image.startAnimation(leftaction);
3d的旋转效果是出来了,至于如何精致,你可自由发挥。
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接