【问题标题】:How to make second fragment overlap on first fragment while fragment transistion如何在片段过渡时使第二个片段重叠在第一个片段上
【发布时间】:2012-08-30 07:57:56
【问题描述】:

我正在处理片段转换。当我用第二个片段替换第一个片段时,它出现在第一个片段的下方。我希望它移动到第一个片段之上。我该怎么做?

fragmentTransaction.setCustomAnimations(animEnter, animExit, animPopEnter, animPopExit);
fragmentTransaction.replace(R.id.fragmentListView, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();

【问题讨论】:

  • 你试过 remove() API
  • 不,我不想删除第一个片段,而是希望第二个片段移动到第一个片段的顶部

标签: android android-fragments android-view android-ui android-custom-view


【解决方案1】:

如果您不想删除第一个片段,您可以使用 add 方法,并将第二个放在第一个之上,您需要引用最顶层的布局或使用 android.R.id.content

例如:

fragmentTransaction.setCustomAnimations(animEnter, animExit, animPopEnter, animPopExit);
fragmentTransaction.add(android.R.id.content, fragment,"MyStringIdentifierTag");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();

这将在当前可见的任何内容之上添加“片段”,而不会删除第一个片段。

【讨论】:

  • 在我们不想填满屏幕的情况下,如何将片段添加到FrameLayout的顶部?
  • 这简直是完美的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-13
  • 1970-01-01
  • 1970-01-01
  • 2020-07-02
相关资源
最近更新 更多