post Animation - Android android.view.animation

Android examples for android.view.animation:Animation

Description

post Animation

Demo Code

import android.animation.Animator;
import android.animation.Animator;
import android.annotation.SuppressLint;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.OvershootInterpolator;
import android.view.animation.TranslateAnimation;

public class Main{

    public static void postAnimation(final View childLayout, int delay,
            final int duration) {
        int visibility = childLayout.getVisibility();
        if (visibility != View.VISIBLE) {
            return;
        }//  w  ww .  j a  v a  2  s .c o m
        childLayout.setVisibility(View.INVISIBLE);
        childLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                childLayout.setVisibility(View.VISIBLE);
                AnimationSet animationSet = new AnimationSet(true);
                animationSet.setDuration(duration);
                animationSet
                        .setInterpolator(new OvershootInterpolator(0.8f));
                int pivotXType = Animation.RELATIVE_TO_SELF;
                animationSet.addAnimation(new TranslateAnimation(
                        pivotXType, -1, pivotXType, 0, pivotXType, 0,
                        pivotXType, 0));
                animationSet.addAnimation(new AlphaAnimation(0, 1));
                childLayout.startAnimation(animationSet);
            }
        }, delay);
    }

}

Related Tutorials