我正在使用 v4 兼容性库并切换到这样的新 fragment :
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();
现在,当我想以编程方式返回到前一个 fragment 而不用新 fragment 事务污染用户的返回堆栈时,我使用 popBackStackImmediate()
:
if (fragmentManager.popBackStackImmediate(fragmentTransactionName, 0)) {
return;
}
// apparently popping back to that fragment was not successful,
// make a regular transaction now
这一切正常,尽管用于为弹出的 fragment 之一设置动画的动画没有反转。我还尝试预先使用 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
,但这甚至没有显示常规事务发生时的转换,也没有显示反向。
我做错了什么?
最佳答案
我会说我必须更好地阅读 The Fine Manual (TM):
public abstract FragmentTransaction setCustomAnimations
(int enter, int exit, int popEnter, int popExit)
"Set specific animation resources to run for the fragments that are entering and exiting in this transaction. The popEnter and popExit animations will be played for enter/exit operations specifically when popping the back stack."
( Source )
关于android - 手动弹出FragmentManager backstack,如何实现逆向交易?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12365215/