Fragment lost transition animation after configuration change

前端 未结 5 1203
独厮守ぢ
独厮守ぢ 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 16:14

    You can use onCreateAnimation plus AnimationUtils for each fragment instead of transaction.setCustomAnimations(..). Also to skip animation during restoring, consider about boleean flag.

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        mIsRestoring = savedInstanceState != null;
        ...
    }
    
    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        if (mIsRestoring) {
            mIsRestoring = false;
            return null;
        }
        if (enter) {
            return AnimationUtils.loadAnimation(getContext(), R.anim.enter_from_right);
        } else {
            return AnimationUtils.loadAnimation(getContext(), R.anim.exit_to_left);
        }
    }
    

提交回复
热议问题