其餘構造器的旋轉也可參考這副圖。 動畫
RotateAnimation旋轉座標系爲以旋轉點爲座標系(0,0)點。x軸爲0度,順時針方向旋轉必定的角度。
1.RotateAnimation(fromDegrees, toDegrees) [默認以View左上角頂點爲旋轉點]。
X軸順時針轉動到fromDegrees爲旋轉的起始點,
X軸順時針轉動到toDegrees爲旋轉的起始點。
如fromDegrees=0,toDegrees=90;爲左上角頂點爲旋轉點。0度爲起始點,90度爲終點。進行旋轉,旋轉了90度
如fromDegrees=60,toDegrees=90;爲左上角頂點爲旋轉點。60度爲起始點,90度爲終點。進行旋轉,旋轉了90-60=30度
2.RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)
(pivotX,pivotY)爲旋轉點。pivotX爲距離左側的偏移量,pivotY爲距離頂部的偏移量。即爲相對於View左上角(0,0)的座標點。
如View width=100px,height=100px
RotateAnimation(0,10,100,100);則以右下角頂點爲旋轉點,從原始位置順時針旋轉10度
RotateAnimation(0,90,50,50);則以View的中心點爲旋轉點,旋轉90度
3.RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue)
pivotXType, pivotXValue, pivotYType, pivotYValue 旋轉點類型及其值。
Animation.ABSOLUTE爲絕對值 其餘爲百分比。這個和平移動畫的同樣,不瞭解能夠去那看
如RotateAnimation(0, 90, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 按中心點旋轉90度
效果和2例中的RotateAnimation(0,90,50,50);則以View的中心點爲旋轉點,旋轉90度 。效果同樣 spa
new RotateAnimation(0, 180, centerX,centerY); io
第一個參數表示動畫的起始角度,第二個參數表示動畫的結束角度,第三個表示動畫的旋轉中心x軸,第四個表示動畫旋轉中心y軸。 float
rotateAnimation.setDuration(1000 * 20); im
表動畫持續20s。 img
rotateAnimation.setFillAfter(true); 移動
ture表示動畫結束後停留在動畫的最後位置,false表示動畫結束後回到初始位置,默認爲false。 di
mView.startAnimation(rotateAnimation); co
表示在mView中啓動動畫。 new