Fragment shared element transition with add() instead of replace()? Fragment shared element transition with add() instead of replace()? android android

Fragment shared element transition with add() instead of replace()?


since the system isnt going through the onPause from the first fragment its not going to happen. becuase when you add a new fragment, the new fragment comes on the top of the old fragment.

but you can fake it though you will have more code !

there is a sample below:

https://github.com/Kisty/FragmentTransitionExample

and a video not compeletely related but helps you to get the idea:

https://www.youtube.com/watch?v=CPxkoe2MraA


Try this

getSupportFragmentManager().beginTransaction()                 .addSharedElement(myImage, "mytransition")                 .add(R.id.recycler_view_container, myFragment2)                 .hide(myFragment1)                   commit(); 

worked for me


Try add .detach() method for FragmentTransaction.

    FragmentManager manager = activity.getSupportFragmentManager ();    Fragment currentFragment = manager.findFragmentById (CONTAINER_ID);     int intoContainerId = currentFragment.getId ();    manager.beginTransaction ()            .setTransition (FragmentTransaction.TRANSIT_FRAGMENT_FADE)            .addSharedElement(view, transitionName)            .addToBackStack (withTag)            .detach(currentFragment)            .add(intoContainerId, newFragment, withTag)            .commit();