Android - Custom Animation on fragment transaction not running

后端 未结 4 881
梦谈多话
梦谈多话 2020-12-12 19:00

I\'m using Google API 8 (Android 2.2) with support package v4.

It doesn\'t give any error or animation.

Transaction:

Fragme         


        
4条回答
  •  盖世英雄少女心
    2020-12-12 19:25

    As suggested above, separate statements will definitely work. But the trick here is to setCustomAnimation before setting transaction type viz.add, replace, etc. else it doesn't. So, applying the same logic, method chaining also works. eg.

    getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations(R.anim.a_slide_up,
                                 R.anim.a_slide_down,
                                 R.anim.a_slide_up,
                                 R.anim.a_slide_down)
            .add(R.id.root_layout, 
                 MyFrag.newInstance())
            .addToBackStack("MyFrag")
            .commit();
    

    Putting it here, so that someone who prefers method chaining finds it helpful. Cheers!

提交回复
热议问题