android 里的2d动画有tween 和frame, 像镜面反转这种动画它内部没有提供支持, 上网查了一下.有人写了这个效果, 但是写得怎一个乱字了得, 又查了一下api demo里就有, 你们还弄什么乱七八糟的啊.http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/animation/Rotate3dAnimation.html如下:

Rotate3dAnimation.java

The file containing the source code shown below is located in the corresponding directory in<sdk>/samples/android-<version>/...

译: 下列包含源码的文件位于相应的<sdk>/samples/android-<version>/...目录下

package com.example.android.apis.animation;

import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.graphics.Camera;
import android.graphics.Matrix;

/**
* An animation that rotates the view on the Y axis between two specified angles.
* This animation also adds a translation on the Z axis (depth) to improve the effect.
译: 一个在指定了两个角度的在Y轴旋转的动画类.
这个类也添加了一个z轴的属性用来提高效果.
*/

publicclassRotate3dAnimationextendsAnimation{
privatefinalfloat mFromDegrees;
privatefinalfloat mToDegrees;
privatefinalfloat mCenterX;
privatefinalfloat mCenterY;
privatefinalfloat mDepthZ;
privatefinalboolean mReverse;
privateCamera mCamera;

/**
* Creates a new 3D rotation on the Y axis. The rotation is defined by its
* start angle and its end angle. Both angles are in degrees. The rotation
* is performed around a center point on the 2D space, definied by a pair
* of X and Y coordinates, called centerX and centerY. When the animation
* starts, a translation on the Z axis (depth) is performed. The length
* of the translation can be specified, as well as whether the translation
* should be reversed in time.
在Y轴创建了一个新的3D的旋转动画,这个旋转动画定义了它的开始角度和结束角度,两个角度的单位都是度数
,这个旋转动画围绕在2D空间的中心点执行.你可以用X轴坐标(叫做
centerX)和Y轴(叫做centerY)坐标来定
义这个中心点.当动画开始时,对于z轴(深度)的转换就会被执行.转换的长度和转换正向反向都可以指定.
  * @param fromDegrees the start angle of the 3D rotation 开始的角度
* @param toDegrees the end angle of the 3D rotation 结束的角度
* @param centerX the X center of the 3D rotation 中心点X轴坐标
* @param centerY the Y center of the 3D rotation 中心点Y轴坐标
* @param reverse true if the translation should be reversed, false otherwise true表示反向,false表示正向

*/

public Rotate3dAnimation(float fromDegrees,float toDegrees,
float centerX,float centerY,float depthZ,boolean reverse){
mFromDegrees
= fromDegrees;
mToDegrees
= toDegrees;
mCenterX
= centerX;
mCenterY
= centerY;
mDepthZ
= depthZ;
mReverse
= reverse;
}

@Override
publicvoid initialize(int width,int height,int parentWidth,int parentHeight){
super.initialize(width, height, parentWidth, parentHeight);
mCamera
=newCamera();
}

@Override
protectedvoid applyTransformation(float interpolatedTime,Transformation t){
finalfloat fromDegrees = mFromDegrees;
float degrees = fromDegrees +((mToDegrees - fromDegrees)* interpolatedTime);

finalfloat centerX = mCenterX;
finalfloat centerY = mCenterY;
finalCamera camera = mCamera;

finalMatrix matrix = t.getMatrix();

camera
.save();
if(mReverse){
camera
.translate(0.0f,0.0f, mDepthZ * interpolatedTime);
}else{
camera
.translate(0.0f,0.0f, mDepthZ *(1.0f- interpolatedTime));
}
camera
.rotateY(degrees);
camera
.getMatrix(matrix);
camera
.restore();

matrix
.preTranslate(-centerX,-centerY);
matrix
.postTranslate(centerX, centerY);
}
}

更多相关文章

  1. Android属性动画(三) TimeInterpolator(插值器)
  2. Android开源DiscreteSeekbar:动画气泡指示当前滑动值
  3. 切换Activity时的动画overridePendingTransition(A,B)解析
  4. android 开机动画和开机视频流程分析基于android4.4
  5. Android(安卓)Animation
  6. Android(安卓)动画系列之自定义补间动画
  7. 【Android(安卓)UI设计与开发】之动画(Animation)详解(一)
  8. Android(安卓)属性动画(Property Animation)介绍
  9. Android中Animator & Animation比较

随机推荐

  1. [置顶] AIDL旅行记之AIDL的简单使用
  2. 如何通过安卓来为自己赚钱
  3. 广播+ Service详解、通知和权限-Android
  4. Android(安卓)Develop Training——和其
  5. comScore:Android作業系統在美國市佔率高
  6. Android(安卓)Trick 6: PendingIntent的
  7. 超好用的Android日志打印框架--Logger
  8. android 创建socket失败
  9. Android(安卓)自定义View(一)可拖动圆环刻
  10. Android(安卓)项目更换头像(拍照和选择相