shrink View Away animation - Android User Interface

Android examples for User Interface:View Animation

Description

shrink View Away animation

Demo Code


//package com.java2s;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

public class Main {
    public static void shinkAway(@NonNull final View v, int shrinkTime,
            @Nullable Animator.AnimatorListener listener) {
        ValueAnimator a = ValueAnimator.ofFloat(1f, 0f);
        a.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override/*from w  w w .  ja va  2s.  co m*/
            public void onAnimationUpdate(@NonNull ValueAnimator animation) {
                v.setScaleX((Float) animation.getAnimatedValue());
                v.setScaleY((Float) animation.getAnimatedValue());
            }
        });
        a.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                v.setVisibility(View.INVISIBLE);
                v.setScaleX(1);
                v.setScaleY(1);
            }
        });
        if (listener != null)
            a.addListener(listener);

        a.setDuration(shrinkTime);
        a.start();
    }
}

Related Tutorials