我想在带有动画的 fragment 之间切换。 目前,我使用这个:
FragmentTransaction fr = getFragmentManager().beginTransaction();
//fr.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
fr.setCustomAnimations(android.R.anim.fade_in,android.R.anim.fade_out);
fr.replace(R.id.fragment_container,new SwimSuitFragment());
fr.addToBackStack(null);
fr.commit();
fade_in
效果很好,但是当我按下返回时它会直接转到前一个 fragment ,并且不执行淡出动画。
最佳答案
来自官方文档;
The popEnter and popExit animations will be played for enter/exit operations specifically when popping the back stack.
public abstract FragmentTransaction setCustomAnimations (int enter,
int exit,
int popEnter,
int popExit)
你应该使用它而不是你的 setCustomAnimations
fr.setCustomAnimations(android.R.anim.fade_in,android.R.anim.fade_out,android.R.anim.fade_in,android.R.anim.fade_out);
关于java - android.R.anim.fade_out 效果不好,只是淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55750468/