Makes view visible and transitions alpha from 0 to 1. - Android User Interface

Android examples for User Interface:View

Description

Makes view visible and transitions alpha from 0 to 1.

Demo Code


//package com.java2s;

import android.animation.ObjectAnimator;
import android.view.View;

public class Main {
    public static final int DEFAULT_FADE_DURATION = 200;

    /**// www.  j  a  v a 2 s. c  o  m
     * Makes view visible and transitions alpha from 0 to 1.  Does nothing if view is
     * already visible.
     *
     * @param view
     * @param duration
     */
    public static void fadeIn(View view, int duration) {
        if (view.getVisibility() == View.VISIBLE) {
            return;
        }
        view.setAlpha(0);
        view.setVisibility(View.VISIBLE);
        ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
        anim.setDuration(duration);
        anim.start();
    }

    /**
     * Fade in with default duration
     *
     * @param view
     */
    public static void fadeIn(View view) {
        fadeIn(view, DEFAULT_FADE_DURATION);
    }
}

Related Tutorials