本文实例讲述了Android编程实现RotateAnimation设置中心点旋转动画效果。分享给大家供大家参考,具体如下:

在xml设置:

android:duration="800" // 设置动画持续时间

android:fromDegrees="0.0" // 设置动画开始时的角度

android:interpolator="@android:anim/linear_interpolator"

android:pivotX="50.0%" // 设置动画相对于控件的x坐标的位置

android:pivotY="50.0%" // 设置动画相对于控件的y坐标的位置

android:repeatCount="infinite" // 设置无线循环

android:toDegrees="360.0" /> // 设置动画结束时的旋转角度

在代码中设置,主要是x,y的坐标为中心点:

public void rotateAnim() {

Animation anim =new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

anim.setFillAfter(true); // 设置保持动画最后的状态

anim.setDuration(3000); // 设置动画时间

anim.setInterpolator(new AccelerateInterpolator()); // 设置插入器

imageview.startAnimation(anim);

}

Android 动画之Interpolator插入器,比较简单和常用的:

(1)LinearInterpolator:动画从开始到结束,变化率是线性变化。

(2)AccelerateInterpolator:动画从开始到结束,变化率是一个加速的过程。

(3)DecelerateInterpolator:动画从开始到结束,变化率是一个减速的过程。

(4)CycleInterpolator:动画从开始到结束,变化率是循环给定次数的正弦曲线。

(5)AccelerateDecelerateInterpolator:动画从开始到结束,变化率是先加速后减速的过程。

希望本文所述对大家Android程序设计有所帮助。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐