在javaeye里看到了关于3d旋转的文章
效果图:
这是你想要的吗?如果是就继续往下看吧。其实,这个效果是用animation配合camera做出来的,相信大家在apidemo里面看过类似的。
那么先写一个继承animation的类:Rotate3d
Rotate3d代码
public class Rotate3d 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 Rotate3d(float fromDegree, float toDegree, float left, float top,
float centerX, float centerY) {
this.mFromDegree = fromDegree;
this.mToDegree = toDegree;
this.mLeft = left;
this.mTop = top;
this.mCenterX = centerX;
this.mCenterY = centerY;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected 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, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
有了这个类一切都会变得简单的,接着只要在activity中写两个Rotate3d的对象,让两个view,分别做这两个对象的animation就好了。(原来就这么简单啊!无语)
Activity代码
//下面两句很关键哦,呵呵,心照不宣。
Rotate3d leftAnimation = new Rotate3d(-0, -90, 0, 0, mCenterX, mCenterY);
Rotate3d rightAnimation = new Rotate3d(-0+90, -90+90, 0.0f, 0.0f, mCenterX, mCenterY);
leftAnimation.setFillAfter(true);
leftAnimation.setDuration(1000);
rightAnimation.setFillAfter(true);
rightAnimation.setDuration(1000);
mImageView1.startAnimation(leftAnimation);
mImageView2.startAnimation(rightAnimation);
还要写一下mImageView1,mImageView2的xml,
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/image1"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image1"
/>
<ImageView
android:id="@+id/image2"
android:background="#ffff0000"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image2"
/>
</FrameLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/image1"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image1"
/>
<ImageView
android:id="@+id/image2"
android:background="#ffff0000"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image2"
/>
</FrameLayout>
</LinearLayout> 写完收工。如果有不足之处,还请朋友们不吝指教。
效果图:
这是你想要的吗?如果是就继续往下看吧。其实,这个效果是用animation配合camera做出来的,相信大家在apidemo里面看过类似的。
那么先写一个继承animation的类:Rotate3d
Rotate3d代码
public class Rotate3d 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 Rotate3d(float fromDegree, float toDegree, float left, float top,
float centerX, float centerY) {
this.mFromDegree = fromDegree;
this.mToDegree = toDegree;
this.mLeft = left;
this.mTop = top;
this.mCenterX = centerX;
this.mCenterY = centerY;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected 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, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
有了这个类一切都会变得简单的,接着只要在activity中写两个Rotate3d的对象,让两个view,分别做这两个对象的animation就好了。(原来就这么简单啊!无语)
Activity代码
//下面两句很关键哦,呵呵,心照不宣。
Rotate3d leftAnimation = new Rotate3d(-0, -90, 0, 0, mCenterX, mCenterY);
Rotate3d rightAnimation = new Rotate3d(-0+90, -90+90, 0.0f, 0.0f, mCenterX, mCenterY);
leftAnimation.setFillAfter(true);
leftAnimation.setDuration(1000);
rightAnimation.setFillAfter(true);
rightAnimation.setDuration(1000);
mImageView1.startAnimation(leftAnimation);
mImageView2.startAnimation(rightAnimation);
还要写一下mImageView1,mImageView2的xml,
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/image1"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image1"
/>
<ImageView
android:id="@+id/image2"
android:background="#ffff0000"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image2"
/>
</FrameLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/image1"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image1"
/>
<ImageView
android:id="@+id/image2"
android:background="#ffff0000"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image2"
/>
</FrameLayout>
</LinearLayout> 写完收工。如果有不足之处,还请朋友们不吝指教。
发表评论
-
android:gravity / android:layout_Gravity,android:padding / android:layout_margin
2012-04-07 15:21 1068android:gravity / android:layou ... -
Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程)
2011-11-18 16:51 8181、当用户触摸屏幕的时候,会产生许多手势,例如down,up, ... -
Android ImageView 总结
2011-11-17 17:17 1199一.介绍 ImageView用来显示任意图像图片,可以自己定义 ... -
简述Android触摸屏手势识别
2011-11-16 16:45 924很多时候,利用触摸屏的Fling、Scroll等Gesture ... -
简述Android触摸屏手势识别
2011-11-16 15:49 914在Android系统中,手势的识别是通过 GestureDet ... -
Android TextView属性详解
2011-11-10 17:12 752android:autoLink设置是否当 ... -
android监听返回按钮事件
2011-11-08 18:38 735用户在点击手机的返回按钮时,默认是推出当前的activty,但 ... -
android 完全退出程序
2011-11-08 18:37 728有几个activity,有一需 ... -
Android onTouchEvent, onClick及onLongClick的调用机制
2011-11-07 15:31 900针对屏幕上的一个View控 ... -
Android WebView放大缩小缩放
2011-11-02 10:27 2531一般情况下通过设置一下参数缩放 wv.getSettings ... -
Android控件之ZoomControls缩放控件
2011-11-01 17:14 1080一、简介 ZoomControls是一组可缩放的控件。它 ... -
Android通过手势实现的缩放处理
2011-11-01 17:12 1028主要原理是onTouchEvent事件中的参数MotionEv ... -
TextView 加下划线
2011-10-30 14:10 967如果是在资源文件里,可以这样写. Xml代码 ... -
Android TextView(EditView)文字底部或者中间加横线
2011-10-30 14:08 1634promotionLinkText = (TextView) ... -
TextView中显示HTML和图片
2011-10-30 13:55 1064在TextView中显示<img src="& ... -
Android 背景图片重复 Background repeat
2011-10-29 00:45 3192以LinearLayout为例,它提供的background属 ... -
android 之 GridView
2011-10-27 14:14 761GridView 的用法基本与ListView类似。 ... -
android GridView的使用
2011-10-27 14:12 1401GridView跟ListView都是比较常用的多控件布局,而 ... -
android之ImageView
2011-10-26 22:17 963ImageView 首先确定下ImageView的全路径: ... -
布局学习—活用RelativeLayout
2011-10-26 00:40 653前言 Android布局中RelativeLayout非 ...
相关推荐
android 3D旋转相册
android 3D旋转效果控件
这是android3D旋转图片的实例,具体请参见博客:http://blog.csdn.net/programchangesworld/article/details/49078387
android 3D旋转屏幕实现,直接解压
android 3D旋转效果
NULL 博文链接:https://chroya.iteye.com/blog/828094
Android 3D圆形旋转菜单Android 3D圆形旋转菜单Android 3D圆形旋转菜单Android 3D圆形旋转菜单Android 3D圆形旋转菜单Android 3D圆形旋转菜单Android 3D圆形旋转菜单Android 3D圆形旋转菜单
对android中3D旋转的代码解释,方便自己学习,如果有android新手的话也可以看看是如何实现的,
这是我在项目中运用的,原本是国外牛人写的,不过有些问题,后来我进行了改进。主要是3D 旋转。类似于dota2 里面选择服务器的界面。
android canvas 3D旋转木马 图片立体展示
实现自动旋转的渐变色立方体
Android自定义动画 3D旋转 在http: blog csdn net a253664942 article details 45601973中有详细解释 有问题可以给我留言
3D自动旋转的旋转木马
1、支持3d旋转。 2、支持自定义旋转。 3、点击3d切换,触摸滑动3d切换 配置view 布局xml里: 代码设置: mLoopRotarySwitchView .setR(300)//设置R的大小 .setAutoRotation(true)//是否自动切换 ....
主要介绍一下如何实现View的3D旋转效果,实现的主要原理就是围绕Y轴旋转,同时在Z轴方面上有一个深入的缩放。 演示的demo主要有以下几个重点: 1,自定义旋转动画 2,动画做完后,重置ImageView
这篇文章主要介绍一下如何实现View的3D旋转效果,实现的主要原理就是围绕Y轴旋转,同时在Z轴方面上有一个深入的缩放。演示的demo主要有以下几个重点: 1,自定义旋转动画 2,动画做完后,重置ImageView 先看一下程序...
Android 随手势进行3D旋转的源码Android 随手势进行3D旋转的源码Android 随手势进行3D旋转的源码Android 随手势进行3D旋转的源码Android 随手势进行3D旋转的源码Android 随手势进行3D旋转的源码Android 随手势进行3D...
android3d绘图 旋转的三角形
Android View 3D旋转
android 3D立体图片旋转,里面是代码项目,直接导入eclipse就可以查看了,可以学习。