ImageView Animated Change - Android User Interface

Android examples for User Interface:ImageView

Description

ImageView Animated Change

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class Main {
    public static void ImageViewAnimatedChange(Context c,
            final ImageView v, final Bitmap new_image) {
        final Animation anim_out = AnimationUtils.loadAnimation(c,
                android.R.anim.fade_out);
        final Animation anim_in = AnimationUtils.loadAnimation(c,
                android.R.anim.fade_in);

        anim_out.setAnimationListener(new Animation.AnimationListener() {
            @Override/* w  ww.j  a  v a  2s  .  c o  m*/
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                v.setImageBitmap(new_image);
                anim_in.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                    }
                });
                if (v != null)
                    v.startAnimation(anim_in);
            }
        });
        if (v != null)
            v.startAnimation(anim_out);
    }
}

Related Tutorials