更新时间:2023-12-02 23:01:10
有 3 种方法可以从视图中移除 Fragment:
There a 3 ways to remove a Fragment from view:
hide
对交易对象的功能)detach
函数)remove
函数)hide
function on transaction object)detach
function on transaction object)remove
function on transaction object)如果您隐藏它,视图将被隐藏,但仍位于布局中并且应该保持不变.如果您分离它,视图将被拆除,但片段仍由 FragmentManager 管理(例如,将在配置更改时重新创建).如果您删除,它将完全从 FragmentManager 中删除,并且将不再管理其状态.
If you hide it the view gets hidden, but is still in the layout and should stay intact. If you detach it, the view gets torn down, but the fragment is still managed by the FragmentManager (and will be recreated on a configuration change, for example). If you remove it it gets removed from the FragmentManager completely and it's state will no longer be managed.