create Slide In From Bottom Animator - Android android.animation

Android examples for android.animation:Animator Slide

Description

create Slide In From Bottom Animator

Demo Code


import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.LinearInterpolator;

public class Main{
    public static Animator createSlideInFromBottomAnimator(View view) {
        DisplayMetrics metrics = getDisplayMetrics(view
                .getContext());//from w ww . j  a  v  a  2  s  . c om

        ObjectAnimator anim = ObjectAnimator.ofFloat(view, "translationY",
                metrics.heightPixels, 0f);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(300);

        return anim;
    }
    public static DisplayMetrics getDisplayMetrics(Context context) {
        if (metrics == null) {
            WindowManager wm = (WindowManager) context
                    .getSystemService(Context.WINDOW_SERVICE);
            metrics = new DisplayMetrics();
            wm.getDefaultDisplay().getMetrics(metrics);
        }

        return metrics;
    }
}

Related Tutorials