Android 3d页面跳转

我们今天来说说怎么样用3D页面跳转。

java代码:
  1. package eoe.demo;


  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.Button;


  7. public class Layout3D extends Activity {
  8. private int mCenterX = 160;
  9. private int mCenterY = 0;

  10. private ViewGroup layout1;
  11. private ViewGroup layout2;

  12. @Override
  13. public void onCreate(Bundle savedInstanceState) {

  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.main);

  16. layout1 = (ViewGroup) findViewById(R.id.layout1);
  17. Button b1 = (Button) findViewById(R.id.button1);
  18. b1.setEnabled(true);
  19. b1.setOnClickListener(new Button.OnClickListener() {
  20. public void onClick(View v) {
  21. leftMoveHandle();
  22. v.setEnabled(false);
  23. }
  24. });
  25. }
  26. public void jumpToLayout1(Rotate3d leftAnimation) {
  27. setContentView(R.layout.main);
  28. layout1 = (ViewGroup) findViewById(R.id.layout1);
  29. layout1.startAnimation(leftAnimation);
  30. Button b1 = (Button) findViewById(R.id.button1);
  31. b1.setEnabled(true);
  32. b1.setOnClickListener(new Button.OnClickListener() {
  33. public void onClick(View v) {
  34. leftMoveHandle();
  35. }
  36. });
  37. }
  38. public void jumpToLayout2(Rotate3d rightAnimation) {
  39. setContentView(R.layout.mylayout);
  40. layout2 = (ViewGroup) findViewById(R.id.layout2);
  41. layout2.startAnimation(rightAnimation);
  42. Button b2 = (Button) findViewById(R.id.button2);
  43. b2.setEnabled(true);
  44. b2.setOnClickListener(new Button.OnClickListener() {
  45. public void onClick(View v) {
  46. rightMoveHandle();
  47. }
  48. });
  49. }
  50. public void leftMoveHandle() {
  51. Rotate3d leftAnimation = new Rotate3d(0, -90, 0, 0, mCenterX, mCenterY);
  52. Rotate3d rightAnimation = new Rotate3d(90, 0, 0.0f, 0.0f, mCenterX, mCenterY);
  53. leftAnimation.setFillAfter(true);
  54. leftAnimation.setDuration(1000);
  55. rightAnimation.setFillAfter(true);
  56. rightAnimation.setDuration(1000);
  57. layout1.startAnimation(leftAnimation);
  58. jumpToLayout2(rightAnimation);
  59. }
  60. public void rightMoveHandle() {
  61. Rotate3d leftAnimation = new Rotate3d(0, 90, 0, 0, mCenterX, mCenterY);
  62. Rotate3d rightAnimation = new Rotate3d(-90, 0, 0.0f, 0.0f, mCenterX,mCenterY);
  63. leftAnimation.setFillAfter(true);
  64. leftAnimation.setDuration(1000);
  65. rightAnimation.setFillAfter(true);
  66. rightAnimation.setDuration(1000);
  67. layout2.startAnimation(rightAnimation);
  68. jumpToLayout1(leftAnimation);
  69. }
  70. }
复制代码
本帖最后由 yida 于 2011-7-29 15:52 编辑

java代码:
  1. package eoe.demo;


  2. import android.graphics.Camera;
  3. import android.graphics.Matrix;
  4. import android.view.animation.Animation;
  5. import android.view.animation.Transformation;


  6. public class Rotate3d extends Animation {
  7. private float mFromDegree;
  8. private float mToDegree;
  9. private float mCenterX;
  10. private float mCenterY;
  11. private float mLeft;
  12. private float mTop;
  13. private Camera mCamera;
  14. private static final String TAG = "Rotate3d";
  15. public Rotate3d(float fromDegree, float toDegree, float left, float top,
  16. float centerX, float centerY) {
  17. this.mFromDegree = fromDegree;
  18. this.mToDegree = toDegree;
  19. this.mLeft = left;
  20. this.mTop = top;
  21. this.mCenterX = centerX;
  22. this.mCenterY = centerY;
  23. }
  24. @Override
  25. public void initialize(int width, int height, int parentWidth,
  26. int parentHeight) {
  27. super.initialize(width, height, parentWidth, parentHeight);
  28. mCamera = new Camera();
  29. }
  30. @Override
  31. protected void applyTransformation(float interpolatedTime, Transformation t) {
  32. final float FromDegree = mFromDegree;
  33. float degrees = FromDegree + (mToDegree - mFromDegree)
  34. * interpolatedTime;
  35. final float centerX = mCenterX;
  36. final float centerY = mCenterY;
  37. final Matrix matrix = t.getMatrix();
  38. if (degrees <= -76.0f) {
  39. degrees = -90.0f;
  40. mCamera.save();
  41. mCamera.rotateY(degrees);
  42. mCamera.getMatrix(matrix);
  43. mCamera.restore();
  44. } else if (degrees >= 76.0f) {
  45. degrees = 90.0f;
  46. mCamera.save();
  47. mCamera.rotateY(degrees);
  48. mCamera.getMatrix(matrix);
  49. mCamera.restore();
  50. } else {
  51. mCamera.save();
  52. //
  53. mCamera.translate(0, 0, centerX);
  54. mCamera.rotateY(degrees);
  55. mCamera.translate(0, 0, -centerX);
  56. mCamera.getMatrix(matrix);
  57. mCamera.restore();
  58. }
  59. matrix.preTranslate(-centerX, -centerY);
  60. matrix.postTranslate(centerX, centerY);
  61. }
  62. }
复制代码

java代码:
  1. package eoe.demo;


  2. import android.app.Activity;
  3. import android.util.Log;
  4. import android.view.MotionEvent;
  5. import android.view.GestureDetector.OnGestureListener;


  6. public class FlingGuest implements OnGestureListener {
  7. Activity activity;
  8. int VALUE_DISTANCE = 100;
  9. int VALUE_SPEED = 20;
  10. public FlingGuest(Activity a) {
  11. activity = a;
  12. }
  13. // 用户轻触触摸屏,由1个MotionEvent ACTION_DOWN触发
  14. public boolean onDown(MotionEvent e) {
  15. Log.d("TAG", "[+++++++++++][onDown]");
  16. return true;
  17. }
  18. // e1, the begin of ACTION_DOWN MotionEvent
  19. // e2, the end of ACTION_DOWN MotionEvent
  20. // velocityX, the motion speed in X
  21. // velocityY:the motion speed in y
  22. // 用户按下触摸屏、快速移动后松开,由1个MotionEvent ACTION_DOWN,
  23. // 多个ACTION_MOVE, 1个ACTION_UP触发
  24. // e1:第1个ACTION_DOWN MotionEvent
  25. // e2:最后一个ACTION_MOVE MotionEvent
  26. // velocityX:X轴上的移动速度,像素/秒
  27. // velocityY:Y轴上的移动速度,像素/秒
  28. // 触发条件 :
  29. // X轴的坐标位移大于VALUE_DISTANCE,且移动速度大于VALUE_SPEED个像素/秒
  30. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
  31. if((e1.getX() - e2.getX() > VALUE_DISTANCE) && Math.abs(velocityX) > VALUE_SPEED) {
  32. ((Layout3D) activity).leftMoveHandle();
  33. }
  34. else if ((e2.getX() - e1.getX() > VALUE_DISTANCE) && Math.abs(velocityX) > VALUE_SPEED) {
  35. ((Layout3D) activity).rightMoveHandle();
  36. }
  37. return true;
  38. }
  39. // 用户长按触摸屏,由多个MotionEvent ACTION_DOWN触发
  40. public void onLongPress(MotionEvent e) {
  41. Log.d("TAG", "[+++++++++++][onLongPress]");
  42. }
  43. // 用户按下触摸屏,并拖动,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE触发
  44. public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
  45. float distanceY) {
  46. Log.d("TAG", "[+++++++++++][onScroll]");
  47. return true;
  48. }
  49. // 用户轻触触摸屏,尚未松开或拖动,由一个1个MotionEvent ACTION_DOWN触发
  50. // 注意和onDown()的区别,强调的是没有松开或者拖动的状态
  51. public void onShowPress(MotionEvent e) {
  52. Log.d("TAG", "[+++++++++++][onShowPress]");
  53. }
  54. // 用户(轻触触摸屏后)松开,由一个MotionEvent ACTION_UP触发
  55. public boolean onSingleTapUp(MotionEvent e) {
  56. Log.d("TAG", "[+++++++++++][onSingleTapUp]");
  57. return true;
  58. }
  59. }

java代码:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:id="@+id/layout1" 
  5. android:layout_height="fill_parent"
  6. android:background="@drawable/black">

  7. <Button android:id="@+id/button1"
  8. android:layout_width="118px"
  9. android:layout_height="wrap_content" 
  10. android:text="Go to Layout2"/>

  11. <TextView android:id="@+id/text1" 
  12. android:textSize="24sp"
  13. android:layout_width="186px" 
  14. android:layout_height="29px"
  15. android:text="@string/layout1" 
  16. android:layout_below="@+id/button1"/>

  17. </RelativeLayout>
复制代码

java代码:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:id="@+id/layout2" 
  5. android:layout_height="fill_parent"
  6. android:background="@drawable/white">
  7. <Button android:id="@+id/button2" 
  8. android:layout_width="118px"
  9. android:layout_height="wrap_content" 
  10. android:text="Go to Layout1">
  11. </Button>
  12. <TextView android:id="@+id/text2" 
  13. android:textSize="24sp"
  14. android:layout_width="186px" 
  15. android:layout_height="29px"
  16. android:textColor="@drawable/black" 
  17. android:text="@string/layout2"
  18. android:layout_below="@+id/button2">
  19. </TextView>
  20. </RelativeLayout>
复制代码
转自: http://www.eoeandroid.com/thread-92161-1-1.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值