Java tutorial
//package com.java2s; //License from project: Open Source License import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; import android.app.Activity; import android.os.Build; import android.view.View; public class Main { @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) public static void showProgress(Activity activity, final View defaultView, final View progressView, final boolean show) { // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow // for very easy animations. If available, use these APIs to fade-in // the progress spinner. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { int shortAnimTime = activity.getResources().getInteger(android.R.integer.config_shortAnimTime); defaultView.setVisibility(show ? View.GONE : View.VISIBLE); defaultView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { defaultView.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); } }); } else { // The ViewPropertyAnimator APIs are not available, so simply show // and hide the relevant UI components. progressView.setVisibility(show ? View.VISIBLE : View.GONE); defaultView.setVisibility(show ? View.GONE : View.VISIBLE); } } }