FragmentTransaction animation to slide in over top

前端 未结 9 1382
星月不相逢
星月不相逢 2020-11-30 20:26

I am trying to achieve the following effect using FragmentTransaction.setCustomAnimations.

  1. Fragment A is showing
  2. Replace Fragment A with Fragment B. F
9条回答
  •  野性不改
    2020-11-30 20:42

    After more experimentation (hence this is my second answer), the problem seems to be that R.anim.nothing means 'disappear' when we want another animation that explicitly says 'stay put.' The solution is to define a true 'do nothing' animation like this:

    Make file no_animation.xml:

    
    
        
        
    
    

    Now simply do as you would otherwise:

    getActivity().getSupportFragmentManager().beginTransaction()
                    .setCustomAnimations(R.anim.slide_in_right, R.anim.no_animation)
                    .replace(R.id.container, inFrag, FRAGMENT_TAG)
                    .addToBackStack("Some text")
                    .commit();
    

提交回复
热议问题