Android SDK 源碼 samples/ApiDemos/src/com/example/android/apis/animation/Rotation3dAnimation.java 已實現完整 3D 翻轉動畫,直接複製到項目即可使用。
Rotation3dAnimation.java 到項目包下。FrameLayout 疊放。Rotation3dAnimation rotation = new Rotation3dAnimation(
frontView, backView, 0, 90, centerX, centerY, 310.0f, true);
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setAnimationListener(new Animation.AnimationListener() {
@Override public void onAnimationEnd(Animation animation) {
frontView.setVisibility(View.GONE);
backView.setVisibility(View.VISIBLE);
}
// ...
});
container.startAnimation(rotation);
fromDegrees/toDegrees:0→90(正面翻到側面),90→180(側面翻到背面)。centerX/Y:旋轉中心,通常為容器中心。depthZ:Z 軸深度(如 310.0f),影響透視感。reverse:true 表示翻轉方向。Camera + Matrix3D 實現。