1.幀動畫(Frame Animation)
屬于視圖動畫,Android1.0引入,Frame Animation命名為AnimationDrawable
2.補間動畫(Tween Animation)
屬于視圖動畫,Android1.0引入,在包android.view.animation下
3.屬性動畫(Property Animation)
Android3.0開始引入,在包android.animation下
4.物理動畫(Physics-based Animations)
2017 Google IO大會提出
一、幀動畫(Frame Animation)
1、用xml文件實現
1.xml文件位置 res/drawable/。
//xml代碼
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/g1"
android:duration="200" />
<item
android:drawable="@drawable/g2"
android:duration="200" />
<item
android:drawable="@drawable/g3"
android:duration="200" />
</animation-list>
//java代碼
//將控件背景設置為我們的AnimationDrawable資源文件
image.setBackgroundResource(R.drawable.frame);
mBinding.play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//拿到要編譯成AnimationDrawable的背景
AnimationDrawable imageAnimation = (AnimationDrawable)image.getBackground();
//開始動畫
imageAnimation.start();
}
});
2.用java代碼實現
二、補間動畫(Tween Animation)
1.用xml動畫文件實現
1.動畫文件位置res/anim
圖片.png
2.用java代碼實現
3.類型
alpha:透明度漸變動畫效果
scale:尺寸變化動畫效果
translate:位置移動動畫效果
rotate:轉移旋轉動畫效果
4.Animation類
直接子類
AnimationSet:代表著一組可以一起播放的動畫。
AlphaAnimation:控制一個對象透明度的動畫。
RotateAnimation:控制一個對象旋轉的動畫。
ScaleAnimation:控制一個對象尺寸的動畫。
TranslateAnimation:控制一個對象位置的動畫。
三、屬性動畫(Property Animation)
1.原理
由TimeInterpolator(插值器)和TypeEvaluator(求值器)完成。
TimeInterpolator計算時間因子,即動畫運行速度,TypeEvaluator計算出具體的屬性值,再通過AnimatorUpdateListener監聽器里的getAnimatedValue()來獲取最新屬性值,來實現View具體某個屬性值的動畫改變。
2.屬性動畫類型
ValueAnimator 針對值變化的Animator。
ObjectAnimator 針對Object變化的Animator。
AnimatorSet 運行一組Animator的集合。
3.Interpolators插值器
TimeInterpolator Animator的插值器接口
4.Evaluators求值器
TypeEvaluator 求值器接口,所有求值器必須實現該接口。
IntEvaluator 計算Int類型的求值器。
FloatEvaluator 計算Float類型的求值器。
ArgbEvaluator 計算顏色值類型的求值器。
四、物理動畫
1.原理
動畫由力驅動
力決定了動畫的加速和減速
在每一幀中動畫值和速度都會更新
當受力達到平衡時動畫停止