簡單總結旋轉、平移、漸變、伸縮動畫
1.通用
alphaAnimation.setFillAfter(true);
設置動畫結束後的狀態,true爲保留最後動畫狀態
2.監聽動畫的開始、結束狀態
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
3.動畫view常用的位置座標信息,view的更多信息,請看。。。未寫,帶總結
TranslateAnimation動畫
TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 來定義動畫
參數說明
float fromXDelta 動畫開始的點離當前View X座標上的差值
float toXDelta 動畫結束的點離當前View X座標上的差值
float fromYDelta 動畫開始的點離當前View Y座標上的差值
float toYDelta 動畫開始的點離當前View Y座標上的差值
常用方法
animation.setDuration(long durationMillis);//設置動畫持續時間
animation.setRepeatCount(int i);//設置重複次數
animation.setRepeatMode(Animation.REVERSE);//設置反方向執行
代碼
TranslateAnimation translateAnimation = new TranslateAnimation(0, 400, 0, 400);
translateAnimation.setDuration(5000);
translateAnimation.setFillAfter(true);
launcherIv.startAnimation(translateAnimation);
ScaleAnimation 動畫
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數說明
float fromX 動畫起始時 X座標上的伸縮尺寸
float toX 動畫結束時 X座標上的伸縮尺寸
float fromY 動畫起始時Y座標上的伸縮尺寸
float toY 動畫結束時Y座標上的伸縮尺寸
int pivotXType 動畫在X軸相對於物件位置類型
float pivotXValue 動畫相對於物件的X座標的開始位置
int pivotYType 動畫在Y軸相對於物件位置類型
float pivotYValue 動畫相對於物件的Y座標的開始位置
代碼
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0, 1, 0, Animation.ABSOLUTE, 400, Animation.ABSOLUTE, -10);
scaleAnimation.setDuration(5000);
scaleAnimation.setFillAfter(true);
launcherIv.startAnimation(scaleAnimation);
RotateAnimation 動畫
RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
參數說明:
float fromDegrees:旋轉的開始角度。
float toDegrees:旋轉的結束角度。
int pivotXType:X軸的伸縮模式,可以取值爲ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X座標的伸縮值。
int pivotYType:Y軸的伸縮模式,可以取值爲ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y座標的伸縮值。
代碼
RotateAnimation rotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(2000);
rotateAnimation.setFillAfter(true);
launcherIv.startAnimation(rotateAnimation);
AlphaAnimation 動畫
AlphaAnimation(float fromAlpha, float toAlpha)
代碼:
AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0.2f);
alphaAnimation.setDuration(1000);
alphaAnimation.setFillAfter(true);
launcherIv.startAnimation(alphaAnimation);