三张图片 中间靠前 两边靠后
1条回答 默认 最新
- 「已注销」 2012-02-08 12:35关注
[code="java"]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.javapackage 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"?>
Android:id="@+id/layout1" android:layout_height="fill_parent"
Android:background="@drawable/black" xmlns:android="http://schemas.android.com/apk/res/android">
Android:layout_height="wrap_content" android:text="Go to Layout2">
Android:layout_width="186px" android:layout_height="29px"
Android:text="@string/layout1" android:layout_below="@+id/button1">
mylayout.xml<?xml version="1.0" encoding="utf-8"?>
Android:id="@+id/layout2" android:layout_height="fill_parent"
Android:background="@drawable/white" xmlns:android="http://schemas.android.com/apk/res/android">
Android:layout_height="wrap_content" android:text="Go to Layout1">
Android:layout_width="186px" android:layout_height="29px"
Android:textColor="@drawable/black" android:text="@string/layout2"
Android:layout_below="@+id/button2">
color.xml<?xml version="1.0" encoding="utf-8"?>
#000000
#FFFFFFFF
[/code]本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 安装svn网络有问题怎么办
- ¥15 Python爬取指定微博话题下的内容,保存为txt
- ¥15 vue2登录调用后端接口如何实现
- ¥65 永磁型步进电机PID算法
- ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
- ¥88 找成都本地经验丰富懂小程序开发的技术大咖
- ¥15 如何处理复杂数据表格的除法运算
- ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥15 latex怎么处理论文引理引用参考文献