【问题标题】:How can I achieve a reversed transition when the FragmentManager's back stack is popped manually?手动弹出 Fragment Manager 回栈时,如何实现反向事务?
【发布时间】:2012-09-11 07:57:08
【问题描述】:

我正在使用 v4 兼容性库并像这样切换到新片段:

 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
 transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
 transaction.replace(R.id.contentFragmentContainer, event.getFragmentClass().newInstance(), FRAGMENT_CONTENT);
 transaction.addToBackStack(fragmentTransactionName);
 transaction.commit();

现在,当我想以编程方式返回前一个片段而不用新的片段事务污染用户的后台堆栈时,我使用popBackStackImmediate()

 if (fragmentManager.popBackStackImmediate(fragmentTransactionName, 0)) {
     return;
 }
 // apparently popping back to that fragment was not successful,
 // make a regular transaction now

这一切都很好,尽管用于动画到弹出片段之一的动画没有反转。我也尝试过事先使用transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE),但是当常规交易发生时,这甚至没有显示转换,也没有显示反向。

我做错了什么?

【问题讨论】:

    标签: android android-fragments transitions


    【解决方案1】:

    我想说我必须更好地阅读 The Fine Manual (TM):

    public abstract FragmentTransaction setCustomAnimations
                    (int enter, int exit, int popEnter, int popExit)
    

    "设置特定的动画资源,为该事务中进入和退出的片段设置运行。popEnter 和 popExit 动画将播放进入/退出操作,特别是在弹出返回堆栈时。"

    (Source)

    【讨论】:

      猜你喜欢
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      相关资源
      最近更新 更多