類 |
xml屬性 |
java實現 |
解釋 |
Animation |
android:duration |
setDuration(long) |
動畫持續時間,毫秒爲單位 |
android:fillAfter |
setFillAfter(boolean) |
控件動畫結束時是否保持動畫最後的狀態 |
|
android:fillBefore |
setFillBefore(boolean) |
控件動畫結束時是否還原到開始動畫前的狀態 |
|
android:fillEnabled |
setFillEnabled(boolean) |
與android:fillBefore效果相同 |
|
android:interpolator |
setInterpolator(Interpolator) |
設定插值器(指定的動畫效果,譬如回彈等) |
|
android:repeatCount |
setRepeatCount(int) |
重複次數 |
|
android:repeatMode |
setRepeatMode(int) |
重複類型有兩個值,reverse表示倒序回放,restart表示從頭播放 |
|
android:startOffset |
setStartOffset(long) |
調用start函數之後等待開始運行的時間,單位爲毫秒 |
2、AlphaAnimation extends Animation; AlphaAnimation的主要屬性都是通過構造函數傳遞,主要屬性如下表:
AlphaAnimation |
android:fromAlpha |
AlphaAnimation(float fromAlpha, ...)
|
動畫開始的透明度,從0.0 --1.0 ,0.0表示全透明,1.0表示完全不透明 |
android:toAlpha |
AlphaAnimation(..., float toAlpha) |
動畫結束的透明度,從0.0 --1.0 ,0.0表示全透明,1.0表示完全不透明 |
3、TranslateAnimation extends Animation,TranslateAnimation中主要的屬性都是通過構造函數傳遞的;
這裏簡單解釋下TranslateAnimation的三個構造函數:
TranslateAnimation(Context context,AttributeSet attrs):這個構造函數是通過xml寫View動畫的時候系統回調的,我們不用管。
TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue,int fromYType, float fromYValue, int toYType, float toYValue)
通過函數的參數我們可以發現XXXType和XXXValue是一一對應的,看字面意思是說,每個Value值可以對應不同Value類型,沒錯,Value類型不同,ValueType的寫法是不一樣的;在Animation中給我們提供了三種ValueType,分別是:
public static final int ABSOLUTE = 0;
public static final int RELATIVE_TO_SELF = 1;
通過傳入這三種value類型,具體的value的寫法也是不一樣的,實現效果也是不一樣的:
valueType
|
value內容 | 解釋 |
ABSOLUTE
|
50
|
絕對的像素值 |
RELATIVE_TO_SELF
|
50%
|
相對於自身寬高的設置百分比,大小:0.0-1.0 浮點數
|
RELATIVE_TO_PARENT
|
50%p
|
相對於父控件的寬高設置百分比,大小0.0-1.0 浮點數
|
TranslateAnimation(float fromXValue, float toXValue, float fromYValue, float toYValue):這個函數中相對於上一個函數的valueType傳值都是ABSOLUTE ,也就是傳入的值都必須是絕對的像素值;
TranslateAnimation |
android:fromXDelta |
TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, |
起始點X軸座標,可以是數值、百分數、百分數p 三種樣式;比如 50、50%、50%p, |
android:toXDelta |
TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, |
結束點X座標,可以是數值、百分數、百分數p 三種樣式;比如 50、50%、50%p, |
|
android:fromYDelta |
TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, |
起始點Y軸從標,可以是數值、百分數、百分數p 三種樣式;比如 50、50%、50%p, |
|
android:toYDelta |
TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, |
結束點Y軸座標,可以是數值、百分數、百分數p 三種樣式;比如 50、50%、50%p, |
ScaleAnimation |
android:fromXScale |
ScaleAnimation(float fromX, float toX, float fromY, float toY, |
起始的X方向上相對自身的縮放比例,浮點值,比如1.0代表自身無變化,0.5代表起始時縮小一倍,2.0代表放大一倍; |
android:toXScale |
ScaleAnimation(float fromX, float toX, float fromY, float toY, |
結尾的X方向上相對自身的縮放比例,浮點值; |
|
android:fromYScale |
ScaleAnimation(float fromX, float toX, float fromY, float toY, |
起始的Y方向上相對自身的縮放比例,浮點值, |
|
android:toYScale |
ScaleAnimation(float fromX, float toX, float fromY, float toY, |
結尾的Y方向上相對自身的縮放比例,浮點值; |
|
android:pivotX |
ScaleAnimation(float fromX, float toX, float fromY, float toY, ) |
縮放起點X軸座標,可以是數值、百分數、百分數p三種樣式,比如 50、50%、50%p;當爲數值時,表示在當前控件的左上角加上50px,做爲起始縮放點;如果是50%,表示在當前控件的左上角加上自己寬度的50%做爲起始點;如果是50%p,那麼就是表示在當前控件的左上角加上父控件寬度的50%做爲起始點x軸座標。 |
|
android:pivotY |
ScaleAnimation(float fromX, float toX, float fromY, float toY, ) |
縮放起點Y軸座標,取值及意義跟android:pivotX一樣。 |
RotateAnimation |
android:fromDegrees |
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue,
|
開始旋轉的角度位置,正值代表順時針方向度數,負值代碼逆時針方向度數 |
android:toDegrees |
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue,
|
結束時旋轉到的角度位置,正值代表順時針方向度數,負值代碼逆時針方向度數 |
|
android:pivotX |
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, (pivotXType默認ABSOLUTE) |
縮放起點X軸座標,可以是數值、百分數、百分數p三種樣式,比如 50、50%、50%p |
|
android:pivotY |
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, (pivotYType默認ABSOLUTE) |
縮放起點Y軸座標,可以是數值、百分數、百分數p三種樣式,比如 50、50%、50%p |
AnimationSet |
<set></set> |
AlphaAnimation |
<alpha></alpha> |
RotateAnimation |
<rotate></rotate> |
TranslateAnimation |
<translate></translate> |
ScalceAnimation |
<scale></scale> |
android:interpolator=""
android:shareInterpolator="">
<scale "通用屬性"+“專有屬性”/>
<rotate "通用屬性"+“專有屬性”/>
<alpha "通用屬性"+“專有屬性”/>
<translate "通用屬性"+“專有屬性”/>
<set>
<scale/>
...
</set>
</set>
AnimationSet animtionSet = AnimationUtils.loadAnimation(context,R.anim.XXX);//加載xml中的動畫布局
由於文章篇幅過長,其他未講到的內容請看下一節;android 動畫-Tween Animation(一)動畫體系簡介,涉及到的核心類、核心接口講解(下)