public static void fadeIn(final View view) {
if (view.getVisibility() == View.VISIBLE) {
return;
}
Animation animation = new AlphaAnimation(0F, 1F);
animation.setDuration(500);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.setEnabled(true);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
view.startAnimation(animation);
view.setVisibility(View.VISIBLE);
}
public static void fadeOut(final 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(500);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
view.startAnimation(animation);
}
使用:
//llcPeakValley.setVisibility(View.GONE);
AnimationUtil.fadeOut(llcPeakValley);
//llcPeakValley.setVisibility(View.VISIBLE);
AnimationUtil.fadeIn(llcPeakValley);
网友评论