平移動畫
// direction :代表進(jìn)入方向 1(上)讯嫂, 2(下), 3(左)欧芽, 4(右)
public static void translateAnimation(int direction, Context context, View view) {
Animation traslate = null;
switch (direction) {
case 1:
traslate = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0);
break;
case 2:
traslate = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0);
break;
case 3:
traslate = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
break;
case 4:
traslate = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
break;
}
if (null != traslate) {
traslate.setDuration(2000);
// 動畫結(jié)束后固定 到 當(dāng)前 位置
traslate.setFillAfter(true);
view.startAnimation(traslate);
}
}
旋轉(zhuǎn)
public static void rotateAnimation(int degree, Context context, View view){
Animation rotate = new RotateAnimation(0, degree, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
if (null != rotate) {
rotate.setDuration(1000);
// 動畫結(jié)束后固定 到 當(dāng)前 位置
rotate.setFillAfter(true);
view.startAnimation(rotate);
}
}
// 縮放動畫
public static void scaleAnimation(Context context, View view){
Animation rotate = new ScaleAnimation(0.1f, 1.1f, 0.1f, 1.1f,Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
if (null != rotate) {
rotate.setDuration(1000);
// 動畫結(jié)束后固定 到 當(dāng)前 位置
rotate.setFillAfter(true);
view.startAnimation(rotate);
}
}
// 透明度
public static void alphaAnimation(Context context, View view) {
Animation alpha = new AlphaAnimation(0.1f, 1.0f);
if (null != alpha) {
alpha.setDuration(1000);
// 動畫結(jié)束后固定 到 當(dāng)前 位置
alpha.setFillAfter(true);
view.startAnimation(alpha);
}
}