天天看點

Android--Animations

為控件使用動畫效果

Animations 就是動畫的意思。Android中的Animations主要用來為控件提供動畫效果。

Animations 總體上分為兩類:

(1)Tweened Animations 即漸變動畫

該類 Animations 提供了旋轉,移動,伸展,和淡出等等效果。

(2)Frame-by-Frame Animations

這一類Animations 可以建立一個Drawable序列,這些Drawable可以按照指定的間隙一個一個顯示。

電影隻要達到一秒24幀就可以了。

Tweened Animations 的分類:

(1)Alpha: 淡入淡出效果。

(2)Scale: 縮放效果。

(3)Rolate: 旋轉效果。

(4)Translate: 移動效果。

使用 Tweened Animations 的步驟

(1)建立一個 AnimationsSet 對象。

(2)根據需要建立相應的 Animation 對象。

(3)為 Animation 對象設定資料。

(4)将 Animation 對象添加到 Animationset 對象當中。

(5)使用控件開始執行 Animationset。

AnimationSet animationSet = new AnimationSet(true);
    AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);// 參數為透明度,1為完全不透明,0為透明。
    // 設定動畫執行時間(機關:毫秒)
    alphaAnimation.setDuration(1000);
    animationSet.addAnimation(alphaAnimation);
    imageView.startAnimation(animationSet);