create Slide Animation - Android android.view.animation

Android examples for android.view.animation:slide Animation

Description

create Slide Animation

Demo Code

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

public class Main{

    public static Animation createSlideAnimation(boolean relToParent,
            boolean horizontal, boolean fromLeftOrTop, boolean exiting,
            int duration) {
        int rel = (relToParent ? Animation.RELATIVE_TO_PARENT
                : Animation.RELATIVE_TO_SELF);
        float movingFrom = (exiting ? 0f : (fromLeftOrTop ? -1f : 1f));
        float movingTo = (exiting ? (fromLeftOrTop ? 1f : -1f) : 0f);
        TranslateAnimation anim;// w w w  .  j  a v  a  2 s .  c  o m
        if (horizontal) {
            anim = new TranslateAnimation(rel, movingFrom, rel, movingTo,
                    rel, 0, rel, 0);
        } else {
            anim = new TranslateAnimation(rel, 0, rel, 0, rel, movingFrom,
                    rel, movingTo);
        }
        anim.setDuration(duration);
        return anim;
    }

}

Related Tutorials