Nested fragments disappear during transition animation

后端 未结 16 1746
广开言路
广开言路 2020-11-29 15:50

Here\'s the scenario: Activity contains fragment A, which in turn uses getChildFragmentManager() to add fragments A1 and A2

16条回答
  •  醉酒成梦
    2020-11-29 16:14

    I was having the same issue with map fragment. It kept disappearing during the exit animation of its containing fragment. The workaround is to add animation for the child map fragment which will keep it visible during the exit animation of the parent fragment. The animation of the child fragment is keeping its alpha at 100% during its duration period.

    Animation: res/animator/keep_child_fragment.xml

        
    
        
    
    

    The animation is then applied when the map fragment is added to the parent fragment.

    Parent fragment

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    
        View view = inflater.inflate(R.layout.map_parent_fragment, container, false);
    
        MapFragment mapFragment =  MapFragment.newInstance();
    
        getChildFragmentManager().beginTransaction()
                .setCustomAnimations(R.animator.keep_child_fragment, 0, 0, 0)
                .add(R.id.map, mapFragment)
                .commit();
    
        return view;
    }
    

    Finally, the duration of the child fragment animation is set in a resource file.

    values/integers.xml

    
      500
    
    

提交回复
热议问题