Layout之间3D切换效果Demo
2011-08-07 23:27
274 查看
1.Layout3D.java
package cn.com; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.Button; public class Layout3D extends Activity { private int mCenterX = 160; private int mCenterY = 0; private ViewGroup layout1; private ViewGroup layout2; private Rotate3d leftAnimation; private Rotate3d rightAnimation; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initFirst(); 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); } }); } public void initFirst(){ leftAnimation = new Rotate3d(0, -90, 0.0f, 0.0f, mCenterX, mCenterY); rightAnimation = new Rotate3d(90, 0, 0.0f, 0.0f, mCenterX, mCenterY); leftAnimation.setFillAfter(true); leftAnimation.setDuration(1000); rightAnimation.setFillAfter(true); rightAnimation.setDuration(1000); } public void initSecond(){ leftAnimation = new Rotate3d(-90, 0, 0.0f, 0.0f, mCenterX, mCenterY); rightAnimation = new Rotate3d(0, 90, 0.0f, 0.0f, mCenterX, mCenterY); leftAnimation.setFillAfter(true); leftAnimation.setDuration(1000); rightAnimation.setFillAfter(true); rightAnimation.setDuration(1000); } public void jumpToLayout1(Rotate3d leftAnimation) { setContentView(R.layout.main); layout1 = (ViewGroup) findViewById(R.id.layout1); layout1.startAnimation(leftAnimation); Button b1 = (Button) findViewById(R.id.button1); b1.setEnabled(true); b1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { leftMoveHandle(); } }); } public void jumpToLayout2(Rotate3d rightAnimation) { setContentView(R.layout.mylayout); layout2 = (ViewGroup) findViewById(R.id.layout2); layout2.startAnimation(rightAnimation); Button b2 = (Button) findViewById(R.id.button2); b2.setEnabled(true); b2.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { rightMoveHandle(); } }); } public void leftMoveHandle() { initFirst(); layout1.startAnimation(leftAnimation); jumpToLayout2(rightAnimation); } public void rightMoveHandle() { initSecond(); layout2.startAnimation(rightAnimation); jumpToLayout1(leftAnimation); } }
Rotate3d.java
package cn.com; import android.graphics.Camera; import android.graphics.Matrix; import android.view.animation.Animation; import android.view.animation.Transformation; 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); } }
3.main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_width="fill_parent" android:id="@+id/layout1" android:layout_height="fill_parent" android:background="@drawable/black" xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:id="@+id/button1" android:layout_width="118px" android:layout_height="wrap_content" android:text="Go to Layout2"> </Button> <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"></TextView> </RelativeLayout>
mylayout.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_width="fill_parent" android:id="@+id/layout2" android:layout_height="fill_parent" android:background="@drawable/white" xmlns:android="http://schemas.android.com/apk/res/android"> <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>
color.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="black">#000000</drawable> <drawable name="white">#FFFFFFFF</drawable> </resources>
相关文章推荐
- Activity之间经典切换动画效果Demo
- Activity之间切换的各种效果(遗憾没有3D的效果)
- android layout 3D切换效果
- Activity之间切换的各种效果(遗憾没有3D的效果)
- Android Activity 之间切换的各种效果
- jQuery插件FusionCharts绘制的3D环饼图效果示例【附demo源码】
- Html5添加三联切换仿3D效果旋转木马jQuery插件教程
- 实现tablayout切换时颜色随之渐变的效果
- fragment之间切换的动画效果设置
- Android两个页面之间的切换效果工具类
- android中2个activity之间的切换动画效果(共12种)
- 【Android游戏开发之五】游戏注册界面Demo-实现两个Activity之间的切换与数据交互!
- DEMO:transition3d、运用动画实现图片3d翻转效果
- 【jQuery Demo】图片切换效果整理
- Android的一个项目中,实现页面之间切换时的动画效果
- jQuery Flux Slider 2D/3D 图片切换效果展示
- Fragment之间切换时onResume效果的使用
- 【iOS开发-24】导航控制器下不同视图控制器之间切换:利用CATrasition和view的layer层来实现自定义的动画效果
- activity 之间切换添加动画效果(一)
- jquery插件jquery.LightBox.js实现点击放大图片并左右点击切换效果(附demo源码下载)