Java tutorial
//package com.java2s; //License from project: Apache License import android.animation.Animator; import android.animation.ObjectAnimator; import android.support.annotation.NonNull; import android.view.View; public class Main { public static final int DURATION_MID = 800; public static void alphaHide(@NonNull final View view, final Runnable rWhenDone) { if (view.getWindowToken() == null) { if (rWhenDone != null) rWhenDone.run(); return; } ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f); alpha.setDuration(DURATION_MID); alpha.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.INVISIBLE); if (rWhenDone != null) rWhenDone.run(); } @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.INVISIBLE); if (rWhenDone != null) rWhenDone.run(); } @Override public void onAnimationRepeat(Animator animation) { } }); alpha.start(); } }