当我使用案例1时,它按预期工作,但使用动画(case2)视图永远不会变得可见!android视图动画和没有动画的行为不同
情况1>
viewstub.setVisibility(View.GONE);
mContentLoaded = false;
showContentOrLoadingIndicator(mContentLoaded);
在此视图将成为无形和有形了!
情况下2>
viewstub.setVisibility(View.GONE);
viewstub.animate().alpha(0f).setDuration(mShortAnimationDuration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
viewstub.setVisibility(View.GONE);
}
});
在此视图将成为无形的,永远不会再变得可见!任何解决方案或原因?
private void showContentOrLoadingIndicator(boolean contentLoaded) {
// Decide which view to hide and which to show.
final View showView = contentLoaded ? listView : mLoadingView;
final View hideView = contentLoaded ? mLoadingView : listView;
// Set the "show" view to 0% opacity but visible, so that it is visible
// (but fully transparent) during the animation.
showView.setAlpha(0f);
showView.setVisibility(View.VISIBLE);
// Animate the "show" view to 100% opacity, and clear any animation
// listener set on
// the view. Remember that listeners are not limited to the specific
// animation
// describes in the chained method calls. Listeners are set on the
// ViewPropertyAnimator object for the view, which persists across
// several
// animations.
showView.animate().alpha(1f).setDuration(mShortAnimationDuration)
.setListener(null);
// Animate the "hide" view to 0% opacity. After the animation ends, set
// its visibility
// to GONE as an optimization step (it won't participate in layout
// passes, etc.)
hideView.animate().alpha(0f).setDuration(mShortAnimationDuration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
hideView.setVisibility(View.GONE);
}
});
}