---------------------main.java---------------------------
package com.example.fe;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
public class MainActivity extends ActionBarActivity {
private float mCenterX;
private float mCenterY;
private View mImageView1;
private View mImageView2;
private RelativeLayout container;
private LinearLayout ll_gt;
private LinearLayout ll_yw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//没有标题栏
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
container = (RelativeLayout) findViewById(R.id.container);
mCenterX = getWindowManager().getDefaultDisplay().getWidth() / 2;
mCenterY = getWindowManager().getDefaultDisplay().getHeight() / 2;
ll_gt = (LinearLayout) findViewById(R.id.ll_gt);
ll_yw = (LinearLayout) findViewById(R.id.ll_yw);
}
public void click_gt(View view) {
startAnimation();
}
public void click_yw(View view) {
startAnimation();
}
int x = 0;
private void startAnimation() {
Rotate3dAnimation outAnimation = new Rotate3dAnimation(0, 90,
mCenterX, mCenterY);
outAnimation.setDuration(500);
outAnimation.setFillAfter(true);
container.startAnimation(outAnimation);
outAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (x == 0) {
ll_yw.setVisibility(View.GONE);
ll_gt.setVisibility(View.VISIBLE);
x=1;
} else {
ll_gt.setVisibility(View.GONE);
ll_yw.setVisibility(View.VISIBLE);
x=0;
}
Rotate3dAnimation inAnimation = new Rotate3dAnimation(270, 360,
mCenterX, mCenterY);
inAnimation.setDuration(500);
inAnimation.setFillAfter(true);
container.startAnimation(inAnimation);
}
});
}
}
--------------------------Rotate3Animation.java----------------------
package com.example.fe;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.Transformation;
public class Rotate3dAnimation extends Animation {
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private Camera mCamera;
public Rotate3dAnimation(float fromDegrees, float toDegrees,
float centerX, float centerY) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
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 fromDegrees = mFromDegrees;
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
。。。。。。。。。。。。。。。main.xml。。。。。。。。。。。。。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/bt" >
<LinearLayout
android:id="@+id/ll_gt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/bt_跟帖"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click_gt"
android:text="跟帖" />
<ImageView
android:id="@+id/image1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:src="@drawable/a4" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_yw"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/bt_yuanwen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click_yw"
android:text="原文" />
<ImageView
android:id="@+id/image2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:src="@drawable/a5" />
</LinearLayout>
</FrameLayout>
</RelativeLayout>