import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
private int mCenterY = 0;
private ViewGroup layout1;
private ViewGroup layout2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
layout1 = (ViewGroup) findViewById(R.id.layout1);
Button b1 = (Button) findViewById(R.id.button1);
b1.setEnabled(true);
b1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
leftMoveHandle();
v.setEnabled(false);
}
});
}
setContentView(R.layout.main);
layout1.startAnimation(leftAnimation);
b1.setEnabled(true);
b1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
leftMoveHandle();
}
});
}
setContentView(R.layout.mylayout);
layout2 = (ViewGroup) findViewById(R.id.layout2);
layout2.startAnimation(rightAnimation);
b2.setEnabled(true);
b2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
rightMoveHandle();
}
});
}
Rotate3d leftAnimation = new Rotate3d(0, -90, 0, 0, mCenterX, mCenterY);
Rotate3d rightAnimation = new Rotate3d(90, 0, 0.0f, 0.0f, mCenterX, mCenterY);
leftAnimation.setDuration(1000);
rightAnimation.setFillAfter(true);
rightAnimation.setDuration(1000);
jumpToLayout2(rightAnimation);
}
Rotate3d leftAnimation = new Rotate3d(0, 90, 0, 0, mCenterX, mCenterY);
Rotate3d rightAnimation = new Rotate3d(-90, 0, 0.0f, 0.0f, mCenterX,mCenterY);
leftAnimation.setDuration(1000);
rightAnimation.setFillAfter(true);
rightAnimation.setDuration(1000);
jumpToLayout1(leftAnimation);
}
}
package cn.com;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.Transformation;
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";
float centerX, float centerY) {
this.mFromDegree = fromDegree;
this.mToDegree = toDegree;
this.mLeft = left;
this.mTop = top;
this.mCenterX = centerX;
this.mCenterY = centerY;
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
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();
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.postTranslate(centerX, centerY);
}
}
import android.util.Log;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
Activity activity;
int VALUE_SPEED = 20;
activity = a;
}
public boolean onDown(MotionEvent e) {
Log.d("TAG", "[+++++++++++][onDown]");
return true;
}
// e2, the end of ACTION_DOWN MotionEvent
// velocityX, the motion speed in X
// velocityY:the motion speed in y
// 用户按下触摸屏、快速移动后松开,由1个MotionEvent ACTION_DOWN,
// 多个ACTION_MOVE, 1个ACTION_UP触发
// e1:第1个ACTION_DOWN MotionEvent
// e2:最后一个ACTION_MOVE MotionEvent
// velocityX:X轴上的移动速度,像素/秒
// velocityY:Y轴上的移动速度,像素/秒
// 触发条件 :
// X轴的坐标位移大于VALUE_DISTANCE,且移动速度大于VALUE_SPEED个像素/秒
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if((e1.getX() - e2.getX() > VALUE_DISTANCE) && Math.abs(velocityX) > VALUE_SPEED) {
((Layout3D) activity).leftMoveHandle();
}
else if ((e2.getX() - e1.getX() > VALUE_DISTANCE) && Math.abs(velocityX) > VALUE_SPEED) {
((Layout3D) activity).rightMoveHandle();
}
return true;
}
public void onLongPress(MotionEvent e) {
Log.d("TAG", "[+++++++++++][onLongPress]");
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
Log.d("TAG", "[+++++++++++][onScroll]");
return true;
}
// 注意和onDown()的区别,强调的是没有松开或者拖动的状态
public void onShowPress(MotionEvent e) {
Log.d("TAG", "[+++++++++++][onShowPress]");
}
public boolean onSingleTapUp(MotionEvent e) {
Log.d("TAG", "[+++++++++++][onSingleTapUp]");
return true;
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/layout1"
android:layout_height="fill_parent"
android:background="@drawable/black">
<Button android:id="@+id/button1"
android:layout_width="118px"
android:layout_height="wrap_content"
android:text="Go to Layout2"/>
<TextView android:id="@+id/text1"
android:textSize="24sp"
android:layout_width="186px"
android:layout_height="29px"
android:text="@string/layout1"
android:layout_below="@+id/button1"/>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/layout2"
android:layout_height="fill_parent"
android:background="@drawable/white">
<Button android:id="@+id/button2"
android:layout_width="118px"
android:layout_height="wrap_content"
android:text="Go to Layout1">
</Button>
<TextView android:id="@+id/text2"
android:textSize="24sp"
android:layout_width="186px"
android:layout_height="29px"
android:textColor="@drawable/black"
android:text="@string/layout2"
android:layout_below="@+id/button2">
</TextView>
</RelativeLayout>