Reveal the provided View with a fade-in animation. - Android Animation

Android examples for Animation:Fade Animation

Description

Reveal the provided View with a fade-in animation.

Demo Code


//package com.java2s;

import android.support.v4.view.ViewCompat;

import android.view.View;

public class Main {
    public static final int ANIMATION_DURATION_SHORTEST = 150;

    public static void fadeInView(View view) {
        fadeInView(view, ANIMATION_DURATION_SHORTEST);
    }//w w w .  ja v  a 2 s .c  om

    /**
     * Reveal the provided View with a fade-in animation.
     *
     * @param view The View that's being animated.
     * @param duration How long should the animation take, in millis.
     */
    public static void fadeInView(View view, int duration) {
        view.setVisibility(View.VISIBLE);
        view.setAlpha(0f);

        // Setting the listener to null, so it won't keep getting called.
        ViewCompat.animate(view).alpha(1f).setDuration(duration)
                .setListener(null);
    }
}

Related Tutorials