public abstract class
Animation
extends Object
implements Cloneable
java.lang.Object
↳ android.view.animation.Animation
Known Direct Subclasses
AlphaAnimation, AnimationSet, RotateAnimation, ScaleAnimation, TranslateAnimation
同AlphaAnimation和TranslateAnimation一样,RotateAnimation和ScaleAnimation动画也都是Animation类的子类。这里一起进行介绍。
RotateAnimation
常用构造方法:
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
fromDegrees:起始角度值
toDegrees: 结束角度值
pivotXType: 转动点X轴的转动标准,共三种,RELATIVE_TO_SELF 以自己为标准,RELATIVE_TO_PARENT以父组件为标准,ABSOLUTE表示绝对位置。
pivotXValue: 针对上面标准的值,取值0-1之间。
pivotYType: 转动点Y轴的转动标准,也是三种,RELATIVE_TO_SELF 以自己为标准,RELATIVE_TO_PARENT以父组件为标准,ABSOLUTE表示绝对位置。
pivotYValue: 针对上面标准的值,取值0-1之间。
下面通过一个实例进行演示:
代码方式实现
1.主布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="demo.androidwar.com.translatedemo.MainActivity">
<Button
android:id="@+id/btn_rotate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:onClick="rotate"
android:text="旋转动画"
android:textSize="20sp" />
<ImageView
android:layout_gravity="center"
android:id="@+id/imgview"
android:layout_width