Fragment 是存在于 Activity 中的可重用 UI 部分 — 是一个模块化的、独立的 UI 组件,具有其自己的生命周期。Fragment 使灵活、可重用的 UI 成为可能,是现代单 Activity 架构的核心。
什么是 Fragment
text
A FRAGMENT = a reusable, modular piece of UI hosted inside an Activity:
→ has its OWN lifecycle (tied to but distinct from the host activity's)
→ multiple fragments can be combined in one activity; reused across activities
→ represents a portion of the screen (or a whole screen's content)
→ Think: an activity can host one or more fragments that make up its UI.
Fragment 与 Activity
text
ACTIVITY → a top-level screen/entry point; heavier; managed by the OS; declared in manifest
FRAGMENT → a UI portion WITHIN an activity; lighter, reusable, modular; managed by the
activity's FragmentManager; NOT declared in the manifest
→ Fragments are more flexible/reusable; activities are the containers/entry points.
