Fragment lost transition animation after configuration change

前端 未结 5 1148
独厮守ぢ
独厮守ぢ 2021-02-01 15:35

I\'m inserting Fragments into the Activity using this code:

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setCon         


        
5条回答
  •  生来不讨喜
    2021-02-01 15:57

    As a workaround for this you can use onCreateAnimator/onCreateAnimation methods in your fragments.

    For example for native fragments implementation:

    @Override
    public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
        if (enter) {
            return AnimatorInflater.loadAnimator(getActivity(), R.animator.slide_in_top);
        } else {
            return AnimatorInflater.loadAnimator(getActivity(), R.animator.fade_out);
        }
    }
    

    The same technique for support library fragments with Animation instead. In this case you also have more control over how would you like to play animation depending upon fragment state and/or arguments.

提交回复
热议问题