Animates the specified view From Top To Bottom - Android User Interface

Android examples for User Interface:View Translate

Description

Animates the specified view From Top To Bottom

Demo Code


//package com.java2s;

import android.view.View;
import android.view.animation.AccelerateInterpolator;

import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

import android.view.animation.ScaleAnimation;

public class Main {
    /**//from  w  ww .jav  a2  s .  c  o m
     * Animates the specified view
     * 
     * @param v
     *            the view to animate
     */
    public static void animateFromTopToBottom(final View v) {
        if (v.getVisibility() == View.VISIBLE) {

            ScaleAnimation animation = new ScaleAnimation(1, 1, 1, 0,
                    Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF,
                    Animation.RELATIVE_TO_SELF, 1);
            animation.setFillAfter(false);
            animation.setDuration(500);
            animation.setInterpolator(new AccelerateInterpolator());
            animation.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    v.setVisibility(View.INVISIBLE);
                }
            });

            v.startAnimation(animation);
        }
    }
}

Related Tutorials