在替换片段时,我使用适用于 android lollipop 版本的幻灯片动画。对于这个特定的替换,它按预期工作,但是在按下后退按钮时,它首先弹出当前片段,然后执行输入动画的反向(滑出)。
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();
}
那么,如何强制幻灯片的反向动画完成后才弹出片段呢?我注意到 Activity 提供了 Finish After Transition() 方法。片段有类似的东西吗?
我遇到了同样的问题,onReturn from Fragment B -> A,Fragment B 似乎正在做额外的幻灯片转换。为了解决这个问题,我添加了淡入淡出过渡setReturnTransition()
比幻灯片的时间短,看起来相当不错(因为它溶解到前一个片段中)。其代码是:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Slide slideRight = new Slide(Gravity.RIGHT);
slideRight.setDuration(200);
fragment.setEnterTransition(slideRight);
Fade fade = new Fade();
fade.setDuration(100);
fragment.setReturnTransition(fade);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)