1. 程式人生 > >Android ObjectAnimator動畫效果實現

Android ObjectAnimator動畫效果實現

一、

ObjectAnimator.ofFloat(imageView, "rotation", 0f, 360f).setDuration(1000).start();

第一個括號引數:圖片控制元件,動畫效果屬性,初始狀態(浮點型),結束狀態(浮點型)。

第二個括號屬性:動畫時間(毫秒)。、

動畫屬行:

1)translationX 和 translationY:這兩個屬性控制了View所處的位置,它們的值是由layout容器設定的,是相對於座標原點(0,0左上角)的一個偏移量。

2)rotation, rotationX 和 rotationY:控制View繞著軸點(pivotX和pivotY)旋轉。

3)scaleX 和 scaleY:控制View基於pivotX和pivotY的縮放。

4)pivotX 和 pivotY:旋轉的軸點和縮放的基準點,預設是View的中心點。

5)x 和 y:描述了view在其父容器中的最終位置,是左上角左標和偏移量(translationX,translationY)的和。

6)aplha:透明度,1是完全不透明,0是完全透明。

二、多個動畫同時顯示,多個動畫時較寫多個一中方法做了優化。

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f, 0f, 200f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f, 0, 200f);
PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f, 0, 200f);
ObjectAnimator.ofPropertyValuesHolder(imageView, pvhX, pvhY,pvhZ).setDuration(1000).start();

三、

ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView, "rotation", 0f, 360f);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView, "scaleX", 0f, 200f);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView, "scaleY", 0f, 200f);
AnimatorSet animSet = new AnimatorSet();
animSet.playTogether(animator1, animator2, animator3 );  //同時執行
//animSet.playSequentially(animator1, animator2, animator3 );  //順序執行
animSet.setDuration(1000);  
animSet.start();     
/** 
* animator2,animator3同時執行 
* animator1接著執行 
*/  
AnimatorSet animSet = new AnimatorSet();  
animSet.play(animator2).with(animator3); 
animSet.play(animator1).after(animator3);  
animSet.setDuration(1000);  
animSet.start(); 

參考:http://blog.csdn.net/lmj623565791/article/details/38067475