2
在2017年Google I/O會議上發言的this part中,演講者介紹了setReorderingAllowed()
的新API,可以在FragmentTransaction
上調用。什麼時候應該在FragmentTransaction上調用setReorderingAllowed()?
揚聲器解釋:
它允許所有執行發生一次全部不改變 您的片段狀態,然後在最後爲大家帶來了所有的 片段需要被提出來,並拆除需要拆除的所有碎片 ...所以我們可以優化這個給你。
,並顯示下面的代碼示例:
fragmentManager.beginTransaction()
.replace(R.id.container, fragment1)
.addToBackStack("state1")
.setReorderingAllowed(true)
.commit();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment2)
.addToBackStack("state2")
.setReorderingAllowed(true)
.commit();
豈不犯FragmentTransaction
小號分別否定該.setReorderingAllowed(true)
給你,因爲它們分別發生任何優化?
由於這是一個新發布的API,因此目前沒有可用的文檔。
「setAllowOptimization」方法在API級別26.0.0-beta2中已棄用,並已重命名爲「setReorderingAllowed(boolean)」。 [Documentation](https://developer.android.com/reference/android/support/v4/app/FragmentTransaction.html#setReorderingAllowed(boolean))現在也可用。 –