public static void fadeIn(View view, float startAlpha, float endAlpha, long duration) {
if (view.getVisibility() == View.VISIBLE) return;
view.setVisibility(View.VISIBLE);
Animation animation = new AlphaAnimation(startAlpha, endAlpha);
animation.setDuration(duration);
view.startAnimation(animation);
}
public static void fadeIn(View view) {
fadeIn(view, 0F, 1F, 400);
// We disabled the button in fadeOut(), so enable it here.
view.setEnabled(true);
}
public static void fadeOut(View view) {
if (view.getVisibility() != View.VISIBLE) return;
// Since the button is still clickable before fade-out animation
// ends, we disable the button first to block click.
view.setEnabled(false);
Animation animation = new AlphaAnimation(1F, 0F);
animation.setDuration(400);
view.startAnimation(animation);
view.setVisibility(View.GONE);
}
网友评论