Show a fragment with shared elements animation

纵然是瞬间 提交于 2019-12-22 10:07:56

问题


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?

来源:https://stackoverflow.com/questions/47742560/show-a-fragment-with-shared-elements-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!