我正在寻找适用于 Android 的 Eclipse IDE,我认为大多数时候我可以执行相同的操作,包括布局或包含 fragment ,因为两者都可以通过 Java 类进行管理。阅读很多帖子后,我不太了解 fragment ......我想我可以在没有它们的情况下创建一个响应式布局,只在我的主布局中包含另一个布局。所以... 您认为在 Android 中包含布局或包含 fragment 之间有什么区别吗? 如果一个选项比另一个更好,你能解释一下吗?
最佳答案
来自Android docs :
A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).
其中重要的部分是 Fragments
有自己的生命周期。这意味着您可以开始、暂停、恢复、停止等 Fragment
。你不能用布局做任何事情。值得注意的是,Fragments
包含它们自己的布局。
关于android - 在 Android 中包含布局或包含 fragment 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23504310/