show Image with Animation - Android Animation

Android examples for Animation:Animation to Show

Description

show Image with Animation

Demo Code


//package com.java2s;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;

public class Main {
    private static AnimationSet showAction;
    private static AnimationSet hideAction;

    public static void showImage(View View, AnimationListener listener) {
        if (showAction == null) {
            initAnimation();//from   w  ww .j  a v a 2 s .  c o  m
        }
        if (View.getVisibility() != View.VISIBLE) {
            View.setVisibility(View.VISIBLE);
            showAction.setAnimationListener(listener);
            View.startAnimation(showAction);
        }
    }

    private static void initAnimation() {
        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(500);
        showAction = new AnimationSet(false);
        showAction.addAnimation(animation);

        animation = new AlphaAnimation(1.0f, 0.2f);
        animation.setDuration(2000);
        hideAction = new AnimationSet(false);
        hideAction.addAnimation(animation);
    }
}

Related Tutorials