本示例为接下来的“SurfaceView使用实例”做铺垫(见 http://www.linuxidc.com/Linux/2012-06/64050.htm )。 先上效果图如下: 要求:沿Y轴正方向看,数值减1时动画逆时针旋转,数值加1时动画顺时针旋转。?实现动画的具体细节见"RotateAnimation.java"。为方便查看动画旋转方向,可以将RotateAnimation.DEBUG值设置为true即可。? ?RotateAnimation参考自APIDemos的Rotate3DAnimation? RotateAnimation的构造函数需有三个参数,分别说明动画组件的中心点位置及旋转方向。? RotateAnimation.initialize()将初始化动画组件及其父容器的宽高;通常亦可进行另外的初始化工作,本例中用于执行对camera进行实例化赋值。? RotateAnimation.applyTransformation()第一个参数为动画的进度时间值,取值范围为[0.0f,1.0f],第二个参数Transformation记录着动画某一帧中变形的原始数据。该方法在动画的每一帧显示过程中都会被调用。? ?在翻转过程中,为了避免在动画下半部分时图像为镜面效果影响数字的阅读,应将翻转角度做180度的减法。代码为RotateAnimation.applyTransformation()中的: if (overHalf) { // 翻转过半的情况下,为保证数字仍为可读的文字而非镜面效果的文字,需翻转180度。 degree = degree - 180; } 动画翻转到一半后,应更新数字内容。为了得知翻转进度,于RotateAnimation中设计一内部静态接口类"InterpolatedTimeListener",该接口只有一个方法"interpolatedTime(float interpolatedTime)"可以将动画进度传递给监听发起者。 Java代码如下,XML请根据效果图自行实现:? |
Android开发教程:文字翻转动画的实现
最新推荐文章于 2021-05-25 17:05:48 发布