共享元素转换在片段中不起作用,同时使用replace()正常工作。当我将appcompat降级到版本v7时:23.1它正在工作它正在工作。我发现这个问题与它的appcompact支持的版本有关,但我找不到任何解决方案。
我用于转换的代码是
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// set transitions
startFragement.setSharedElementReturnTransition(TransitionInflater.from(
activity).inflateTransition(R.transition.change_image_trans));
startFragement.setExitTransition(TransitionInflater.from(
activity).inflateTransition(android.R.transition.fade));
endFragment.setSharedElementEnterTransition(TransitionInflater.from(
activity).inflateTransition(R.transition.change_image_trans));
endFragment.setEnterTransition(TransitionInflater.from(
activity).inflateTransition(android.R.transition.fade));
// send bunddle string of transition_name in endfragment
/*Bundle bundle = new Bundle();
bundle.putString(GistConstants.TRANSITION_NAME, transition_name);
endFragment.setArguments(bundle);*/
FragmentTransaction fragmentTransaction = ((AppCompatActivity)activity).getSupportFragmentManager().beginTransaction();
Fragment currentFragment = ((FragmentActivity)activity).getSupportFragmentManager().findFragmentById(R.id.main_content);
if(currentFragment!= null) {
fragmentTransaction.hide(currentFragment);
}
if(isAddToStack){
fragmentTransaction.addToBackStack(endFragment.getClass().getName());
}
fragmentTransaction.addSharedElement(transitionImageView, transition_name);
fragmentTransaction.add(R.id.main_content, endFragment, endFragment.getClass().getName());
//fragmentTransaction.add(contentId, endFragment,endFragment.getClass().getName());
// fragmentTransaction.replace(R.id.main_content, endFragment);
fragmentTransaction.commitAllowingStateLoss();
} else {
switchFragmentAdd(activity, endFragment, isAddToStack, isAnimate);
}
答案 0 :(得分:0)
适用于 v7:25.1.1 但返回转换不起作用:
startFragement.setSharedElementReturnTransition(TransitionInflater.from(
activity).inflateTransition(R.transition.change_image_trans)