3

In my app I have code like this:

final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, fragment, "tag");
transaction.addSharedElement(view, "transitionName");
transaction.addToBackStack(null)
    .commit();

It works fine, shared elements animation works. But if I change this code like

getSupportFragmentManager().beginTransaction()
                .add(R.id.fragment_container, fragment, "tag")
                .hide(fragment)
                .commit();

final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.remove(oldFragment);
transaction.show(fragment);
transaction.addSharedElement(view, "transitionName");
transaction.addToBackStack(null)
    .commit();

Shared elements animation is not working here. But on d.android.com it is written that addSharedElement "Used with to map a View from a removed or hidden Fragment to a View from a shown or added Fragment." So is it a bug or I am doing wrong something?

Kiryl Tkach
  • 3,118
  • 5
  • 20
  • 36

0 Answers0