4. Building a Dynamic UI with Fragments 使用片段构建动态UI
To create a dynamic and multi-pane user interface on Android, you need to encapsulate UI components and activity behaviors into modules that you can swap into and out of your activities. You can create these modules with the Fragment
class, which behaves somewhat like a nested activity that can define its own layout and manage its own lifecycle.
要在Android上创建一个动态和多窗格的用户界面,您需要将UI组件和活动行为封装到可以插入和移出活动的模块中。 您可以使用Fragment类创建这些模块,其行为有点像可以定义自己的布局并管理自己的生命周期的嵌套活动。
When a fragment specifies its own layout, it can be configured in different combinations with other fragments inside an activity to modify your layout configuration for different screen sizes (a small screen might show one fragment at a time, but a large screen can show two or more).
当片段指定自己的布局时,它可以配置为与活动中的其他片段不同的组合,以修改不同屏幕大小的布局配置(一个小屏幕可能一次显示一个片段,但是大屏幕可以显示两个或 更多)。
This class shows you how to create a dynamic user experience with fragments and optimize your app's user experience for devices with different screen sizes, all while continuing to support devices running versions as old as Android 1.6.
该课程向您展示如何创建具有片段的动态用户体验,并针对具有不同屏幕尺寸的设备优化应用的用户体验,同时继续支持运行与Android 1.6相同版本的设备。