android 简单动画
2018-05-24 本文已影响0人
XX杰
平移动画
// direction :代表进入方向 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);
// 动画结束后固定 到 当前 位置
traslate.setFillAfter(true);
view.startAnimation(traslate);
}
}
旋转
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);
// 动画结束后固定 到 当前 位置
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);
// 动画结束后固定 到 当前 位置
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);
// 动画结束后固定 到 当前 位置
alpha.setFillAfter(true);
view.startAnimation(alpha);
}
}