除了addToBackStack之外,将包含片段的布局的可见性设置为GONE
和fragmentTransaction.hide(fragment)
之间是否有任何主要区别?
答案 0 :(得分:8)
fragmentTransaction.hide(fragment)
public void hideFragment(Fragment fragment, int transition, int transitionStyle) {
if (DEBUG) Log.v(TAG, "hide: " + fragment);
if (!fragment.mHidden) {
fragment.mHidden = true;
if (fragment.mView != null) {
Animator anim = loadAnimator(fragment, transition, true,
transitionStyle);
if (anim != null) {
anim.setTarget(fragment.mView);
// Delay the actual hide operation until the animation finishes, otherwise
// the fragment will just immediately disappear
final Fragment finalFragment = fragment;
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (finalFragment.mView != null) {
finalFragment.mView.setVisibility(View.GONE);
}
}
});
anim.start();
} else {
fragment.mView.setVisibility(View.GONE);
}
}
if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.onHiddenChanged(true);
}
}
所以它几乎一样,但它
View
返回的Fragment#onCreateView()
设置为GONE
而不是容器