首页 > 系统 > Android > 正文

Android编程实现RotateAnimation设置中心点旋转动画效果

2019-10-22 18:15:39
字体:
来源:转载
供稿:网友

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

在xml设置:

<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android"  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程序设计有所帮助。


注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表