Shared transition with getChildFragmentManager() n

2019-04-09 07:44发布

问题:

I implement fragments as below:

  1. Activity to hold parent fragment. Uses getSupportFragmentManager() to add Parent fragment.
  2. In parent fragment I use getChildFragmentManager() and transaction to replace childFragment.
  3. In childFragment I again call childFragment and so on....
  4. Everything work fine except shared transition.'
  5. If I use getFragmentManager() instead of getChildFragmentManager() then there is shared transition but then there is not concept of getChildFragmentManager().

The code sample looks like:

/*This code does not show animation*/
getChildFragmentManager()
                .beginTransaction()
                .addSharedElement(transitionView, ViewCompat.getTransitionName(transitionView))
                .replace(R.id.fragment_container, categoryDetailChildFragment)
                .addToBackStack(TAG)
                .commit();

and the code that shows animation is:

  getFragmentManager()
                .beginTransaction()
                .addSharedElement(transitionView, ViewCompat.getTransitionName(transitionView))
                .replace(R.id.fragment_container, categoryDetailChildFragment)
                .addToBackStack(TAG)
                .commit();

Why there is no shared transition when getChildFragmentManager()? Please help anybody.