在Android中,您可以使用以下方法在动画完成后隐藏视图:
ViewPropertyAnimator
:View viewToHide = findViewById(R.id.view_to_hide);
viewToHide.animate()
.alpha(0)
.setDuration(1000)
.withEndAction(new Runnable() {
@Override
public void run() {
viewToHide.setVisibility(View.GONE);
}
});
Animation
:View viewToHide = findViewById(R.id.view_to_hide);
AlphaAnimation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setDuration(1000);
fadeOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// Do nothing
}
@Override
public void onAnimationEnd(Animation animation) {
viewToHide.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
// Do nothing
}
});
viewToHide.startAnimation(fadeOut);
TransitionManager
:ViewGroup viewGroup = findViewById(R.id.view_group);
View viewToHide = findViewById(R.id.view_to_hide);
TransitionManager.go(new Scene(viewGroup), new AutoTransition()
.setDuration(1000)
.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
// Do nothing
}
@Override
public void onTransitionEnd(Transition transition) {
viewToHide.setVisibility(View.GONE);
}
@Override
public void onTransitionCancel(Transition transition) {
// Do nothing
}
@Override
public void onTransitionPause(Transition transition) {
// Do nothing
}
@Override
public void onTransitionResume(Transition transition) {
// Do nothing
}
}));
这些方法可以帮助您在动画完成后隐藏视图,而不需要提及其他云计算品牌商。
领取专属 10元无门槛券
手把手带您无忧上云