RotateAnimation類:旋轉變化動畫類的使用和總結

RotateAnimation類是Android系統中的旋轉變化動畫類,用於控制View對象的旋轉動作,該類繼承於Animation類。RotateAnimation類中的很多方法都與Animation類一致,該類中最常用的方法便是RotateAnimation構造方法。

一、
public RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

參數說明
fromDegrees:旋轉的開始角度。
toDegrees:旋轉的結束角度。
pivotXType:X軸的伸縮模式,可以取值爲ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
pivotXValue:X座標的伸縮值。
pivotYType:Y軸的伸縮模式,可以取值爲ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
pivotYValue:Y座標的伸縮值。

pivotXType, pivotXValue, pivotYType, pivotYValue  旋轉點類型及其值。
Animation.ABSOLUTE爲絕對值 其他爲百分比。這個和平移動畫的一樣
如RotateAnimation(0, 90, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 按中心點旋轉90度

順時針方向旋轉爲正值,逆時針方向旋轉爲負值


二、
RotateAnimation(fromDegrees, toDegrees) [默認以View左上角頂點爲旋轉點]。
參數說明
fromDegrees:旋轉的開始角度。
toDegrees:旋轉的結束角度。

三、
RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)
參數說明
以(pivotX,pivotY)爲旋轉點。從fromDegrees旋轉到toDegrees。pivotX爲距離左側的偏移量,pivotY爲距離頂部的偏移量。即爲相對於View左上角(0,0)的座標點。
如View width=100px,height=100pxRotateAnimation(0,10,100,100);則以右下角頂點爲旋轉點,從原始位置順時針旋轉10度

四、
new RotateAnimation(0, 180, centerX,centerY);
第一個參數表示動畫的起始角度,第二個參數表示動畫的結束角度,第三個表示動畫的旋轉中心x軸,第四個表示動畫旋轉中心y軸。


五、
rotateAnimation.setDuration(1000 * 20);
表動畫持續20s。

六、
rotateAnimation.setFillAfter(true);
ture表示動畫結束後停留在動畫的最後位置,false表示動畫結束後回到初始位置,默認爲false。

七、
mView.startAnimation(rotateAnimation);

表示在mView中啓動動畫。


更加詳細的Animation資料見:

http://www.cnblogs.com/feisky/archive/2010/01/11/1644482.html

http://blog.csdn.net/zhy_cheng/article/details/7951092

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章