gpt4 book ai didi

android - fragmentTransaction.hide 和 setVisibility(GONE) 之间的区别;

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:11 25 4
gpt4 key购买 nike

除了 addToBackStack 之外,将包含 fragment 的布局可见性设置为 GONEfragmentTransaction.hide(fragment) 之间有什么主要区别吗?

最佳答案

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);
}
}

所以它的作用几乎相同,但是它

  • 支持动画
  • 支持后台
  • Fragment#onCreateView() 返回的 View 设置为 GONE 而不是容器
  • 如果您在其中添加了 fragment ,则负责菜单

关于android - fragmentTransaction.hide 和 setVisibility(GONE) 之间的区别;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com