共享元素转换不适用于appcompat支持的库版本v7中的FragmentTransaction.add():23.2.0

时间:2016-08-24 11:41:25

标签: java android android-appcompat android-transitions shared-element-transition

使用appcompat最新版本执行FragmentTransaction.add()时,

共享元素转换在片段中不起作用,同时使用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);
    }

1 个答案:

答案 0 :(得分:0)

适用于 v7:25.1.1 但返回转换不起作用:

startFragement.setSharedElementReturnTransition(TransitionInflater.from(
                activity).inflateTransition(R.transition.change_image_trans)