先將以下程式加入專案。
public class Flip3dAnimation extends Animation { private final float mFromDegrees; private final float mToDegrees; private final float mCenterX; private final float mCenterY; private Camera mCamera; public Flip3dAnimation(float fromDegrees, float toDegrees, float centerX, float centerY) { mFromDegrees = fromDegrees; mToDegrees = toDegrees; mCenterX = centerX; 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 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(); camera.rotateY(degrees); camera.getMatrix(matrix); camera.restore(); matrix.preTranslate(-centerX, -centerY); matrix.postTranslate(centerX, centerY); } }
使用方法:
如果你是要點擊按鈕或item以後轉跳畫面,想要等動畫跑完再轉跳畫面,可以用以下方法,
600代表0.6秒後再轉跳畫面
final float centerX = view.getWidth() / 2.0f; final float centerY = view.getHeight() / 2.0f; final Flip3dAnimation rotation = new Flip3dAnimation(0, 90, centerX, centerY); rotation.setDuration(500); rotation.setFillAfter(true); rotation.setInterpolator(new AccelerateInterpolator()); view.startAnimation(rotation); view.postDelayed(new Runnable() { public void run() { //do things here } },600);
沒有留言:
張貼留言