shared element transition works with FragmentTransaction.replace() but doesn't work with FragmentTransaction.add()

前端 未结 3 662
囚心锁ツ
囚心锁ツ 2020-12-14 16:54

The new Shared Element Transitions works when i use Fragment \'replace\' but i can\'t seem to make it work fragment \'add\'. I use the same container in bo

3条回答
  •  轮回少年
    2020-12-14 17:52

    It will not animate because the old fragment is still present. For adding you need to hide the previous fragment. Here is the example

    For pushing:

        fragmentTransaction.add(R.id.content, fragment);
        if (fragments.size() > 0) {
            UIBaseFragment lastElement = fragments.lastElement();
            fragmentTransaction.hide(lastElement);
        }
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
        fragments.push(fragment);
    

    Then pop in this way

        final FragmentManager manager = getChildFragmentManager();
        manager.popBackStack();
        fragments.pop();
    

提交回复
热议问题