Android培训翻译_使用Fragment创建动态UI

 

本文是Android开发官网 Android培训的中文翻译,限于译者水平有限,便于大家指正,采用中英文对照风格,原文见

http://developer.android.com/intl/zh-CN/training/basics/fragments/index.html

更多已翻译内容请见 Android培训翻译_目录

 

Fragment通常被译为“片段”,本文将保留专有名次的英文不做翻译


 

Dependencies and prerequisites 依赖关系和先决条件

  • Basic knowledge of the Activity lifecycle (see Managing the Activity Lifecycle).
    Activity 生命周期的基础知识(见 管理Activity生命周期)
  • Experience building XML layouts.
    构建XML 布局的经验。

You should also read 你也应该阅读

Try it out 尝试

下载示例 (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.
在Android上创建动态的、多窗格的用户界面,你需要将UI组件和Activity行为封装成模块,这样你可以在你的多个Actvity中装入或者换出。你可以使用Fragment类创建这些模块,它表现的像个嵌套的Activity,可以定义自己的布局并管理自己的生命周期。

 

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).
当一个fragment指定了它自己的布局,它便可以和Activity中的其它fragment配置成不同的组合以修改在不同屏幕尺寸上的布局(小屏幕一次可能只显示一个fragment,但是大屏幕可以一次显示两个或更多)。

 

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.
这节课将向你展示如何用fragment创建一个动态的用户体验,并在不同屏幕尺寸的设备上优化您应用程序的用户体验,同时继续支持在Android 1.6一样老的版本上运行。

 

Lessons 课程


Using the Android Support Library
使用 Android 支持库
Learn how to use more recent framework APIs in earlier versions of Android by bundling the Android Support Library into your app.
学习如何通过绑定Android支持库,以在早期的Android版本中使用最新的框架API。
Creating a Fragment
创建一个Fragment
Learn how to build a fragment and implement basic behaviors within its callback methods.
学习如何构建一个fragment 并用其回调方法实现其基本行为。
Building a Flexible UI
构建灵活的用户界面
Learn how to build your app with layouts that provide different fragment configurations for different screens.
了解如何构建你的应用程序,使用了不同fragment配置的布局来支持不同的屏幕。
Communicating with Other Fragments
与其它Fragment通信
Learn how to set up communication paths from a fragment to the activity and other fragments.
了解如何设置从一个fragment到Activity或者到其它fragment的通信路径。

posted on 2012-08-21 13:49  梵谷星辰  阅读(2069)  评论(0编辑  收藏  举报

导航