I have a view pager which contains 4 completely different fragments.
From fragment A of that pager I want to create a new Fragment like this:
Transition changeTransform = TransitionInflater.from(getActivity()).inflateTransition(R.transition.change_image_transform);
Transition explodeTransform = TransitionInflater.from(getActivity()).inflateTransition(android.R.transition.explode);
// Setup exit transition on first fragment
setSharedElementReturnTransition(changeTransform);
setExitTransition(explodeTransform);
// Setup enter transition on second fragment
PropertyFragment fragment = new PropertyFragment();
fragment.setSharedElementEnterTransition(changeTransform);
fragment.setEnterTransition(explodeTransform);
FragmentTransaction ft = getChildFragmentManager().beginTransaction()
.replace(R.id.container, fragment)
.addToBackStack(fragment.getFragmentTag())
.addSharedElement(icon, icon.getTransitionName())
.addSharedElement(text, text.getTransitionName());
ft.commit();
R.id.Container is the parent RelativeLayout of of FragmentA(not the activity's) R.transition.change_image_transform is the following:
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeTransform />
<changeBounds />
<changeImageTransform/>
</transitionSet>
The fragment transaction works and the explodeTransform happens. But the shared element transitions aren't working. It's like they are not even there. I've tried programmatically creating the transition instead of XML with all the combinations of these:, , i could. Nothing works. The transition names are correct on both ends 100%.
I have also tried getChildFragmentManager(), getactivity().getSupportFragmentManager() for the transaction but it doesn't make any change either.
Also the transition works when the staring fragment doesn't belong to a Viewpager. So the problem is there. Do you have any ideas about this? I have also found this: Fragment shared element transitions don't work with ViewPager which I believe is the same as mine but the solution only works with Activity transitions so it doesn't really help.