添加新片段时隐藏上一个片段

时间:2012-03-01 13:33:07

标签: android android-fragments

我有2 Fragment的 - A和B. 为了从Fragment A切换到Fragment B我正在使用此功能:

public static void swapFragments(FragmentManager fragmentManager, int containerViewId, Fragment newFragment)    {

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(containerViewId, newFragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

假设Fragment A占据整个屏幕的区域,而Fragment B仅占据屏幕的上半部分。

问题:切换到Fragment B时,用户仍然可以在屏幕的下半部分看到Fragment A ...

切换到Fragment B时如何隐藏Fragment A?

ps:我不想在上面的replace函数中使用add代替swap - 我不希望Fragment A onCreate()每次用户从Fragment B导航回Fragment A ...

时调用

提前致谢。

2 个答案:

答案 0 :(得分:0)

你可以移动Fragment A吗?例如。片段B出现时滑下来?只需将其移出屏幕即可。类似this question

中讨论的内容

答案 1 :(得分:0)

好吧,没有任何其他选择,我只是注意Fragment B将占据整个屏幕,以便Fragment A无法看到。

由于Android的错误,应该进行更多调整,例如:Google's stupid bug

相关问题