ScaleAnimation動畫是用來進行縮放的動畫,我在使用時剛開始有些不解的問題
后來經過學習,有了一個更深的了解。
先來看看源碼,其實ScaleAnimation有四個構造函數,這里我只列出了其中的一個,因為
另外的三個其實都只是這個構造函數的一種特殊情況,這里我就只分析這個構造函數。
參數如下
float fromX 動畫起始時 X坐標上的伸縮尺寸
float toX 動畫結束時 X坐標上的伸縮尺寸 ??
float fromY 動畫起始時Y坐標上的伸縮尺寸 ??
float toY 動畫結束時Y坐標上的伸縮尺寸 ??
int pivotXType 動畫在X軸相對于物件位置類型 ??
float pivotXValue 動畫相對于物件的X坐標的開始位置 ??
int pivotYType 動畫在Y軸相對于物件位置類型 ??
float pivotYValue 動畫相對于物件的Y坐標的開始位置 ?
說明
fromX,fromY
代表著你的這個View動畫執行開始時的X軸方向和Y軸方向的縮放
尺寸,當為1.0f時就代表這和原來大小相同,當為2.0就是在X軸或Y軸方向上2倍尺寸大小。
toX,toY
和上邊一樣,代表著你的這個View動畫執行結束時的X軸方向和Y軸方向的縮放
尺寸。
pivotXType,pivotYType
代表著這個View動畫執行的過程中你指定的伸縮原點相對于你的物件位置如何設置的方式。它共有三種
模式,分別為Animation.ABSOLUTE,Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT
分別代表著絕對位置,相對于自己和相對于父布局的模式。當使用第一種時,比較簡單,就是說把整個
動畫的縮放中心點設置在一個相對于你的View的一個絕對位置處。當使用Animation.RELATIVE_TO_SELF和Animation.RELATIVE_TO_PARENT
就代表著你設定伸縮原點時使用相對位置,這個相對位置的參照物可以是你自己也可以是父布局。
pivotYValue,pivotXValue
這兩個參數是和上面兩個參數相關聯的,也就是說當我們使用上面的兩個參數設置好我們相對于物件位置類型時,
我們使用這兩個參數來說明我們到底把這個伸縮原點放到哪里。這里我們就不討論Animation.ABSOLUTE這種情況了
,比較簡單。我們討論Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT這兩種模式下的參數的使用。
這兩個參數是float類型,是相對的位置值,例如當你使用RELATIVE_TO_SELF模式并設置pivotXValue的值為0.5時,
就是說你的X軸方向的伸縮點設在你的這個View的X軸方向的中點處,同樣如果你在把Y軸設為一樣的方式。那么也就確定了
你的動畫執行時的縮放原點為你的View的中心處,從這個中心點開始變大或縮小。
后來經過學習,有了一個更深的了解。
先來看看源碼,其實ScaleAnimation有四個構造函數,這里我只列出了其中的一個,因為
另外的三個其實都只是這個構造函數的一種特殊情況,這里我就只分析這個構造函數。
/*** Constructor to use when building a ScaleAnimation from code* * @param fromX Horizontal scaling factor to apply at the start of the* animation* @param toX Horizontal scaling factor to apply at the end of the animation* @param fromY Vertical scaling factor to apply at the start of the* animation* @param toY Vertical scaling factor to apply at the end of the animation* @param pivotXType Specifies how pivotXValue should be interpreted. One of* Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or* Animation.RELATIVE_TO_PARENT.* @param pivotXValue The X coordinate of the point about which the object* is being scaled, specified as an absolute number where 0 is the* left edge. (This point remains fixed while the object changes* size.) This value can either be an absolute number if pivotXType* is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.* @param pivotYType Specifies how pivotYValue should be interpreted. One of* Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or* Animation.RELATIVE_TO_PARENT.* @param pivotYValue The Y coordinate of the point about which the object* is being scaled, specified as an absolute number where 0 is the* top edge. (This point remains fixed while the object changes* size.) This value can either be an absolute number if pivotYType* is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.*/public ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) {mResources = null;mFromX = fromX;mToX = toX;mFromY = fromY;mToY = toY;mPivotXValue = pivotXValue;mPivotXType = pivotXType;mPivotYValue = pivotYValue;mPivotYType = pivotYType;initializePivotPoint();}
參數如下
float fromX 動畫起始時 X坐標上的伸縮尺寸
float toX 動畫結束時 X坐標上的伸縮尺寸 ??
float fromY 動畫起始時Y坐標上的伸縮尺寸 ??
float toY 動畫結束時Y坐標上的伸縮尺寸 ??
int pivotXType 動畫在X軸相對于物件位置類型 ??
float pivotXValue 動畫相對于物件的X坐標的開始位置 ??
int pivotYType 動畫在Y軸相對于物件位置類型 ??
float pivotYValue 動畫相對于物件的Y坐標的開始位置 ?
說明
fromX,fromY
代表著你的這個View動畫執行開始時的X軸方向和Y軸方向的縮放
尺寸,當為1.0f時就代表這和原來大小相同,當為2.0就是在X軸或Y軸方向上2倍尺寸大小。
toX,toY
和上邊一樣,代表著你的這個View動畫執行結束時的X軸方向和Y軸方向的縮放
尺寸。
pivotXType,pivotYType
代表著這個View動畫執行的過程中你指定的伸縮原點相對于你的物件位置如何設置的方式。它共有三種
模式,分別為Animation.ABSOLUTE,Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT
分別代表著絕對位置,相對于自己和相對于父布局的模式。當使用第一種時,比較簡單,就是說把整個
動畫的縮放中心點設置在一個相對于你的View的一個絕對位置處。當使用Animation.RELATIVE_TO_SELF和Animation.RELATIVE_TO_PARENT
就代表著你設定伸縮原點時使用相對位置,這個相對位置的參照物可以是你自己也可以是父布局。
pivotYValue,pivotXValue
這兩個參數是和上面兩個參數相關聯的,也就是說當我們使用上面的兩個參數設置好我們相對于物件位置類型時,
我們使用這兩個參數來說明我們到底把這個伸縮原點放到哪里。這里我們就不討論Animation.ABSOLUTE這種情況了
,比較簡單。我們討論Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT這兩種模式下的參數的使用。
這兩個參數是float類型,是相對的位置值,例如當你使用RELATIVE_TO_SELF模式并設置pivotXValue的值為0.5時,
就是說你的X軸方向的伸縮點設在你的這個View的X軸方向的中點處,同樣如果你在把Y軸設為一樣的方式。那么也就確定了
你的動畫執行時的縮放原點為你的View的中心處,從這個中心點開始變大或縮小。