Android 图片转动效果(一)

我们先来看看效果图:

<ignore_js_op>190302td1aajjrtgddurnt.jpg

<ignore_js_op>1903047yc2vg49ycpqpc4x.jpg


看见效果就是旋转前和旋转后的效果

       如果是你想要的效果,那么继续往下看,如果不是,那可以跳过了。这是一个动画,而不是用matrix实现的直接翻转图片。
       我这个是根据APIDemo,简单修改写的需要一个Rotate3d,类,继承,Animation这个类可以直接拷过去,不用做任何的修改。其中的方法自己找相关资料研究。

java代码:

public class Rotate3d extends Animation{ 

 

private final float mFromDegrees; 

 

private final float mToDegrees; 

 

private final float mCenterX; 

 

private final float mCenterY; 

 

private final float mDepthZ; 

 

private final boolean mReverse; 

 

private Camera mCamera; 

 

public Rotate3d(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 

 

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(); 

 

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); 

 

 

复制代码

 

 
posted @ 2012-12-20 14:14  GreyWolf  阅读(430)  评论(0编辑  收藏  举报