安卓(Android) 怎么按效果获取动画(Animation)

2019年10月16日22:57:55安卓(Android) 怎么按效果获取动画(Animation)已关闭评论 208 2034字阅读6分46秒

1.简介

安卓(Android) 怎么按效果获取动画(Animation)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */



import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;

public class Main {
    public final static int ANIMATION_FADE_IN = 1;
    public final static int ANIMATION_FLIP_IN = 2;
    public final static int ANIMATION_SLIDE_IN_BOTTOM = 3;
    public final static int ANIMATION_SLIDE_IN_LEFT = 4;
    public final static int ANIMATION_SLIDE_IN_RIGHT = 5;
    public final static int ANIMATION_SLIDE_IN_TOP = 6;

    public static AnimationSet getEnterAnimationSet(int animation) {
        AnimationSet set = new AnimationSet(false);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        alphaAnimation.setDuration(3000);
        set.addAnimation(alphaAnimation);
        TranslateAnimation translateAnimation;

        switch (animation) {
        case ANIMATION_FADE_IN:
            return set;
        case ANIMATION_FLIP_IN:
            return set;
        case ANIMATION_SLIDE_IN_BOTTOM:
            translateAnimation = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 1.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f);
            translateAnimation.setDuration(1000);
            set.addAnimation(translateAnimation);
            return set;
        case ANIMATION_SLIDE_IN_LEFT:
            translateAnimation = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, -1.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f);
            translateAnimation.setDuration(1000);
            set.addAnimation(translateAnimation);
            return set;
        case ANIMATION_SLIDE_IN_RIGHT:
            translateAnimation = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 1.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f);
            translateAnimation.setDuration(1000);
            set.addAnimation(translateAnimation);
            return set;
        case ANIMATION_SLIDE_IN_TOP:
            translateAnimation = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, -1.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f);
            translateAnimation.setDuration(1000);
            set.addAnimation(translateAnimation);
            return set;
        default:
            return null;
        }
    }
}

 
继续阅读
编程十万个怎么办