前面介绍了利用Android自带的控件,进行滑动翻页制作效果,现在我们通过代码实现一些滑动翻页的动画效果。
Animation实现动画有两个方式:帧动画(frame-by-frame animation)和补间动画(tweened animation)
本示 例通过继承Animation自定义Rotate3D,实现3D翻页效果。效果图如下:
1、Rotate3D(Animation)
首先,自定义Animation的3D动画类Rotate3D
public class Rotate3D extends Animation { private float fromDegree; // 旋转起始角度 private float toDegree; // 旋转终止角度 private float mCenterX; // 旋转中心x private float mCenterY; // 旋转中心y private Camera mCamera; public Rotate3D(float fromDegree, float toDegree, float centerX, float centerY) { this.fromDegree = fromDegree; this.toDegree = toDegree; this.mCenterX = centerX; this.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 FromDegree = fromDegree; float degrees = FromDegree + (toDegree - fromDegree) * interpolatedTime; // 旋转角度(angle) 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); // 位移x mCamera.rotateY(degrees); mCamera.translate(0, 0, -centerX); mCamera.getMatrix(matrix); mCamera.restore(); } matrix.preTranslate(-centerX, -centerY); matrix.postTranslate(centerX, centerY); } }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索private
, float
, animation
, 想进阶的android渣
, 滑动翻页
, applytransformation
, 自定义控件旋转android
, android matrix
, 3D旋转动画
, Camera旋转
, Android翻页效果
Android答题器翻页
android 旋转滑动、android 滑动旋转卡片、3d滑动旋转切换图片、unity 滑动旋转模型、unity 3d滑动手指旋转,以便于您获取更多的相关知识。