[mobilesafe] 04_手机杀毒-病毒查杀UI-扫描病毒的旋转动画效果-RotateAnimation

Android 4.0

扫描病毒的旋转动画效果-RotateAnimation

1、动画的Interpolator 动画的进度使用interpolator控制,android提供了几个Interpolator   子类,实现了不同的速度曲线,如LinearInterpolator实现了匀速效果、Accelerateinterpolator实现了加速效果、DecelerateInterpolator实现了减速效果等。还可以定义自己的Interpolator子类,实现抛物线、自由落体等物理效果。
<set android:interpolator="@android:anim/accelerate_interpolator">
    ...
</set>
2、rotate动画旋转的中心点
android:pivotX
android:pivotY
代表以什么为中心:
a) 
pixels  像素
"5" : 表示自己的左上角的距离5像素  the object's left edge
b) 
percentage 百分比   
"5%":表示自己的左上角的距离为自己的宽度或者高度的5%   the object's left edge
"5%p":表示父窗体的左上角的5%的位置   the parent container's left edge

1、代码开启动画
// 1、使用代码定义动画,播放动画
RotateAnimation ra = new RotateAnimation(0, 360,Animation.RELATIVE_TO_PARENT, 0.5f,Animation.RELATIVE_TO_PARENT, 0.5f);
ra.setDuration(2000);
ra.setRepeatCount(Animation.INFINITE);
ra.setInterpolator(new LinearInterpolator());// 匀速旋转
iv_scan_malware.startAnimation(ra);
2、使用xml文件配置动画,播放
1) anti_virus_walware.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 9、扫描病毒的转动动画 -->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0.0" 
    android:toDegrees="360.0"
    android:pivotX="50%p"
    android:pivotY="50%"
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="2000"
    android:repeatCount="infinite"
    >
</rotate>
2) 代码开启动画
// 2、使用xml文件方式定义的动画
RotateAnimation ra = (RotateAnimation) AnimationUtils.loadAnimation(this, R.anim.anti_virus_walware);
iv_scan_malware.startAnimation(ra);  
效果: