我在一个活动中有两个片段,我想让第一个片段从屏幕左侧平稳滑出视图,同时第二个片段从屏幕右侧进入视图。我正在使用Transitions API,以下是发生的情况:
初始屏幕:
转换效果差:
我的代码如下:
HomeFragment savedHomeFragment = (HomeFragment) getSupportFragmentManager().findFragmentByTag(HOME_FRAGMENT);
if (savedHomeFragment == null) {
mHomeFragment = new HomeFragment();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mHomeFragment.setEnterTransition(new Fade(Fade.MODE_IN));
mHomeFragment.setExitTransition(new Slide(Gravity.START));
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.placeholder, mHomeFragment, HOME_FRAGMENT);
fragmentTransaction.commit();
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
savedHomeFragment.setEnterTransition(new Fade(Fade.MODE_IN));
savedHomeFragment.setExitTransition(new Slide(Gravity.START));
}
}
void buttonClick() {
TargetFragment targetFragment = new TargetFragment();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
targetFragment.setEnterTransition(new Slide(Gravity.END));
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.placeholder, targetFragment , TARGET_FRAGMENT);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
我做错了什么?