I am trying to make a shared element transition between fragments, everything works fine when using replace()
to add the second fragment, however in the codebase add()
is used a lot, but when using that, transition just skips to end values
Is it possible to have the transition between added fragments? Thanks
@Override public void onClick(View v) { setSharedElementReturnTransition(TransitionInflater.from(getActivity()) .inflateTransition(android.R.transition.move)); FragmentB secondFragment = new FragmentB(); secondFragment.setSharedElementEnterTransition(TransitionInflater.from(getActivity()) .inflateTransition(android.R.transition.move)); getFragmentManager().beginTransaction() .add(R.id.container, secondFragment) .addToBackStack(null) .addSharedElement(imageView, imageView.getTransitionName()) .commit(); }
Use replace() to replace an existing fragment in a container with an instance of a new fragment class that you provide. Calling replace() is equivalent to calling remove() with a fragment in a container and adding a new fragment to that same container.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With