get Animation by effect - Android Animation

Android examples for Animation:Animation Creation

Description

get Animation by effect

Demo Code


//package com.java2s;

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:/*from   w  w w. j  a va  2  s .  c om*/
            return null;
        }
    }
}

Related Tutorials