天天看點

菜單

首先,看下效果:

菜單
菜單

首先,看下xml檔案:

大家看到主要有三個RalativeLayout,就是大家看到的三層,但是關于圖檔的傾斜 是怎樣實作的呢?實際上是個假象,圖檔是正放的,裡面圖像是傾斜的。如下圖:

菜單

這樣大概能明白,下面就是開始動畫效果了,先看下主Activity:

應該注意到了:

看一下這個靜态方法的實作:

RotateAnimation是畫面轉移旋轉動畫效果,看一下它的構造方法:

RotateAnimation(Context context, AttributeSet attrs)

Constructor used when a RotateAnimation is loaded from a resource.

RotateAnimation(float fromDegrees, float toDegrees)

Constructor to use when building a RotateAnimation from code.

RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)

Constructor to use when building a RotateAnimation from code

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坐标的伸縮值。

關于角度問題:

關于pivotXValue:這一點的X坐标的對象被旋轉,在指定的絕對數字0是左邊邊緣。如果pivotXType數是絕對的這個值可以是一個絕對,另外也可以是百分比(在1.0為100%)。50%是x中點,100%為右邊緣。

同理,pivotYValue:這一點的Y坐标的對象被旋轉,在指定的絕對數字0是頂部邊緣。如果pivotYType數是絕對的這個值可以是一個絕對,另外也可以是百分比(在1.0為100%)。50%是Y中點,100%為下邊緣。

然後再看下調用的其他的方法:

setFillAfter:

If fillAfter is true, the transformation that this animation performed will persist when it is finished. Defaults to false if not set. Note that this applies when using an AnimationSet to chain animations. The transformation is not applied before the AnimationSet itself starts.

如果fillAfter為真,transformation 動畫将一直運作直到它完成。預設設定為假。注意:這适用于當使用一個AnimationSet連鎖動畫。transformation 是不适用AnimationSet本身之前開始。

setDuration:設定動畫時間。

再看一下退出:

有一個animation.setStartOffset(startOffset);是設定animation多長時間以後執行。

繼續閱讀