我使用以下代码将片段添加到活动中。当用户点击按钮时,它从底部滑入,当按下按钮时,它应滑出到底部。为此,我实现了setCustomAnimation(int, out, popEnter, popExit)
。 According to the doc,popExit
动画在后退时播放。
幻灯片部分工作正常,但片段只是在背面按下时从屏幕上消失,而不是播放popExit
动画。
下次用户按下按钮(调用addFragment
)以显示片段时,幻灯片播放(popExit
)动画将在播放动画之前播放。 知道为什么吗?
public void addFragment(Fragment){
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.addToBackStack(f.getClass().getSimpleName());
fragmentTransaction.setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_out_to_bottom,R.anim.slide_in_from_bottom, R.anim.slide_out_to_bottom);
fragmentTransaction.add(R.id.fragment_container, f);
fragmentTransaction.commit();
}