且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在选项卡更改时调用 Android 片段 oncreateview

更新时间:2023-12-02 23:01:10

有 3 种方法可以从视图中移除 Fragment:

There a 3 ways to remove a Fragment from view:

  • 隐藏它(hide 对交易对象的功能)
  • 分离它(交易对象上的detach函数)
  • 移除它(交易对象上的remove函数)
  • Hide it (hide function on transaction object)
  • Detach it (detach function on transaction object)
  • Remove it (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.