Fragment間轉場可以使用setTransition()來設置系統默認的轉場動畫,也可以使用setCustomAnimations()方法來自定義轉場動畫。
getFragmentManager().beginTransaction() //An optional name for this back stack state, or null.addToBackStack()方法的參數如前面所說也可以為null
.addToBackStack(null)//將替換的前一個事務添加的有Activity管理的返回棧中 //通過setCustomAnimation()方法來自定義Fragment間的過渡動畫,前兩個參數代表進入Fragment的動畫效果,后兩個參數代表退出Fragment的動畫效果
.setCustomAnimations(R.anim.slide_in_right, R.anim.hold,R.anim.hold,R.anim.slide_out_right) .remove(this)//移除原來的Fragment
.replace(R.id.content_2, fragment) .commit();
abstractFragmentTransaction |
setCustomAnimations(int enter, int exit, int popEnter, int popExit) Set specific animation resources to run for the fragments that are entering and exiting in this transaction. |
abstractFragmentTransaction |
setCustomAnimations(int enter, int exit) Set specific animation resources to run for the fragments that are entering and exiting in this transaction. |