to top

用Fragment构建一个动态UI

Dependencies and prerequisites

You should also read

Try it out

Download the sample

FragmentBasics.zip

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.

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.

Lessons

Using the Android Support Library
Learn how to use more recent framework APIs in earlier versions of Android by bundling the Android Support Library into your app.
创建一个Fragment
Learn how to build a fragment and implement basic behaviors within its callback methods.
搭建一个灵活的UI
Learn how to build your app with layouts that provide different fragment configurations for different screens.
与其他的Fragment通信
Learn how to set up communication paths from a fragment to the activity and other fragments.