toggle Progress View - Android User Interface

Android examples for User Interface:View

Description

toggle Progress View

Demo Code


//package com.java2s;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;

import android.view.View;

public class Main {
    public static void toggleProgress(final View progressView,
            final View otherView, final boolean show) {
        if (progressView.getVisibility() == View.VISIBLE && show)
            return;

        int shortAnimTime = progressView.getResources().getInteger(
                android.R.integer.config_shortAnimTime);

        otherView.setVisibility(show ? View.GONE : View.VISIBLE);
        otherView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
                .setListener(new AnimatorListenerAdapter() {
                    @Override/* w w w.jav a 2 s.c o  m*/
                    public void onAnimationEnd(Animator animation) {
                        otherView.setVisibility(show ? View.GONE
                                : View.VISIBLE);
                    }
                });

        progressView.setVisibility(show ? View.VISIBLE : View.GONE);
        progressView.animate().setDuration(shortAnimTime)
                .alpha(show ? 1 : 0)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        progressView.setVisibility(show ? View.VISIBLE
                                : View.GONE);
                    }
                });
    }
}

Related Tutorials