项目中 用到控件的旋转效果 ,研究了一下 这里做个记录

旋转类 

Rotate3d

package com.appdoll.rotate3dtest;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 fromDegree;// 旋转起始角度private float toDegree;// 旋转终止角度private float mCenterX;// 旋转中心xprivate float mCenterY;// 旋转中心yprivate Camera mCamera;public Rotate3d(float fromDegree, float toDegree, float centerX, float centerY) {this.fromDegree = fromDegree;this.toDegree = toDegree;this.mCenterX = centerX;this.mCenterY = centerY;}@Overridepublic void initialize(int width, int height, int parentWidth, int parentHeight) {super.initialize(width, height, parentWidth, parentHeight);mCamera = new Camera();}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) {final float FromDegree = fromDegree;float degrees = FromDegree + (toDegree - fromDegree) * 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);}}

activity

package com.appdoll.rotate3dtest;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.util.DisplayMetrics;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.Toast;public class Rotate3dTestActivity extends Activity {private ViewGroup layout1,layout2;Button btnNext1, btnNext2;private Rotate3d layout1Animation ,layout2Animation;private int mCenterX, mCenterY;Context context=this;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        layout1 = (ViewGroup) findViewById(R.id.layout1);        layout2 = (ViewGroup) findViewById(R.id.layout2);        btnNext1 = (Button) layout1.findViewById(R.id.btn_next1);        btnNext2 = (Button) layout2.findViewById(R.id.btn_next2);                initAnimation();        btnNext1.setOnClickListener(listener);        btnNext2.setOnClickListener(listener);    }    private View.OnClickListener listener = new View.OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch(v.getId()){case R.id.btn_next1:Toast.makeText(context, "next1", 0).show();layout1.startAnimation(layout1Animation);layout2.startAnimation(layout2Animation);break;case R.id.btn_next2:Toast.makeText(context, "next2", 0).show();layout2.startAnimation(layout1Animation);layout1.startAnimation(layout2Animation);break;}}        };    public void initAnimation(){DisplayMetrics dm = new DisplayMetrics();dm = getResources().getDisplayMetrics();mCenterX = dm.widthPixels / 2;mCenterY = dm.heightPixels / 2;   int duration = 1000;layout1Animation = new Rotate3d(0, -90, mCenterX, mCenterY);layout1Animation.setFillAfter(true);layout1Animation.setDuration(duration);layout2Animation = new Rotate3d(90, 0, mCenterX, mCenterY);layout2Animation.setFillAfter(true);layout2Animation.setDuration(duration);    }}

布局

<?xml version="1.0" encoding="utf-8"?>                


更多相关文章

  1. Android 属性动画中心点无限循环
  2. 【转载】Android事件分发机制完全解析,带你从源码的角度彻底理解(
  3. Android事件分发机制完全解析,带你从源码的角度彻底理解
  4. [置顶] 从源码角度分析Android View的绘制机制(一)
  5. 从性能角度选购Adroid智能手机,双核、大屏与游戏的取舍
  6. 【转载】Android事件分发机制完全解析,带你从源码的角度彻底理解(
  7. Android之百度地图开发,包含定位,覆盖物,经纬度位置转换,长按设置中
  8. Android的启动过程分析(从进程和Framework的角度)-android学习之

随机推荐

  1. Android用户界面 UI组件--TextView及其子
  2. Paint---PathEffect(路径效果)
  3. [Android(安卓)SQLite]数据存储与访问 -
  4. Android(安卓)应用第一次运行时,引导页面
  5. (详解)Eclipse3.6搭建 Android(安卓)2.2
  6. Android(安卓)--启动画面制做 png图片-->
  7. android学习01
  8. Android(安卓)Zxing 扫描条码实现竖屏模
  9. Android开发经验谈之应用间数据共享
  10. Android(安卓)Studio使用技巧系列教程(七)