在替换片段时,我正在使用适用于 android 棒棒糖版本的幻灯片动画。对于这个特定的替换,它按预期工作,但是在按下后退按钮时,它首先弹出当前片段,然后执行输入动画的反向(滑出)。
private void replaceContentFrameByFragment(Fragment replaceBy, String replaceByFragmentTag) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Slide slide = new Slide(Gravity.BOTTOM);
slide.setDuration(1000);
replaceBy.setEnterTransition(slide);
}
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, replaceBy, replaceByFragmentTag);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commitAllowingStateLoss();
}
那么,如何在幻灯片的反向动画完成后才强制片段弹回?我注意到活动提供了方法 finishAfterTransition() 。片段有类似的东西吗?