RotateAnimation是Andriod中的补间(Tween)动画中的旋转动画
使用时,需要在res下新建Android Resource Directtory,并选择anim(如已存在就不需要重复建)。在anim文件夹下new一个Animation Resource File,并在Root element中填写rotate即可。
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android">
</rotate>
rotate自有属性:fromDegrees、toDegrees、pivotX、pivotY。
- fromDegrees:属性为动画起始旋转的角度位置,正值代表顺时针方向度数,负值代码逆时针方向度数,0代表原位置。
- toDegrees:属性为动画从起始旋转的角度位置转到结束时的角度位置。正值代表顺时针方向度数,负值代码逆时针方向度数,0代表原位置。注意起始为0,终点为360时,会旋转1圈。
- pivotX:属性为旋转中心的X坐标。
- pivotY:属性为旋转中心的Y坐标。
eg:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="720"
android:toDegrees="1800"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000">
</rotate>
上面代码表示从顺时针720度时旋转至顺时针1800度(实际效果为从原位置转3圈),旋转中心为此view的中心(50%处),动画时长5秒。duration为父类属性,表示动画时长。