fragment-activitys

来源:互联网 发布:盘古数据公司怎么样 编辑:程序博客网 时间:2024/06/14 18:31

这是官方文档,我闲下来翻译了一下,希望有用处,我先截取一点下:

Fragments

http://cs.szpt.edu.cn/android/guide/components/fragments.html

A Fragment represents a behavior or a portion of user interface in an Activity.

一个片段是一个行为或在一个活动用户界面的一部分.

You can combine multiplefragments in a single activity to build a multi-pane UI and reuse a fragment inmultiple activities.

可以结合多个碎片在一个单一的活动建立一个多窗格UI和重用一个片段在多个活动。

 You can think of a fragment as a modularsection of an activity, which has its own lifecycle, receives its own inputevents, and which you can add or remove while the activity is running (sort oflike a "sub activity" that you can reuse in different activities).

你能想到的一个片段是一个模块化的一个活动,它有自己的生命周期,收到自己的输入事件,您可以添加或删除活动运行时(就像一个子活动”,您可以重用在不同的活动)

A fragment must always beembedded in an activity and the fragment's lifecycle is directly affected bythe host activity's lifecycle.

一个片段必须嵌入在一个活动和片段的生命周期直接影响主机活动的生命周期.

 For example, when the activity is paused, soare all fragments in it, and when the activity is destroyed, so are all fragments.

例如,当活动暂停,所以都是碎片,当活动被摧毁,所以都是碎片。

 However, while an activity is running (it isin theresumedlifecyclestate), you can manipulate each fragment independently, such as add orremove them.

然而,而一个正在运行的活动(这是在resumed生命周期状态),你可以控制每一个片段independently,这样的添加或删除它们.

 When you perform such a fragment transaction,you can also add it to a back stack that's managed by the activity—each backstack entry in the activity is a record of the fragment transaction thatoccurred.

当您执行这样一个片段交易,你也可以将它添加到堆栈的管理活动中的活动回堆栈条目的记录片段发生的事务。

The back stack allows theuser to reverse a fragment transaction (navigate backwards), by pressing theBack button.

回堆栈允许用户改变片段事务(向后导航),按后退按钮。

When you add a fragmentas a part of your activity layout, it lives in aViewGroup inside the activity's view hierarchy and the fragment defines its ownview layout.

当你添加一个片段的一部分活动布局,它生活在ViewGroup内部活动的视图层次和片段定义了自己的视图布局。

You can insert a fragmentinto your activity layout by declaring the fragment in the activity's layoutfile, as a<fragment> element, or from yourapplication code by adding it to an existingViewGroup.

你可以插入一个片段活动布局,宣布活动的布局文件的片段,<片段>元素,或从您的应用程序代码添加到现有ViewGroup

However, a fragment isnot required to be a part of the activity layout; you may also use a fragmentwithout its own UI as an invisible worker for the activity.

然而,片段不需要活动布局的一部分,你也可以使用一个片段没有自己的UI的一个看不见的工人活动。

This document describeshow to build your application to use fragments, including how fragments canmaintain their state when added to the activity's back stack, share events withthe activity and other fragments in the activity, contribute to the activity'saction bar, and more.

本文档描述如何构建您的应用程序使用片段,包括碎片如何能保持其状态添加到活动回来时堆栈,分享事件与活动和其他碎片的活动,导致活动的操作栏,和更多。

 

DesignPhilosophy(设计原理)

Android introducedfragments in Android 3.0 (API level 11), primarily to support more dynamic andflexible UI designs on large screens, such as tablets. Because a tablet'sscreen is much larger than that of a handset, there's more room to combine andinterchange UI components.

Android介绍片段在Android 3.0(API级别11),主要是为了支持更多的动态和灵活的UI设计的大屏幕上,如平板电脑。因为平板电脑的屏幕比手机更大,有更多的空间组合和交换UI组件

 

Fragments allow suchdesigns without the need for you to manage complex changes to the viewhierarchy.

碎片允许这样的设计不需要你来管理复杂的视图层次的变化。

By dividing the layout ofan activity into fragments, you become able to modify the activity's appearanceat runtime and preserve those changes in a back stack that's managed by theactivity.

除以一个活动成了碎片的布局,你就能够在运行时修改活动的外观和保存这些更改的回堆栈管理的活动。

For example, a newsapplication can use one fragment to show a list of articles on the left andanother fragment to display an article on the right—both fragments appear inone activity, side by side, and each fragment has its own set of lifecyclecallback methods and handle their own user input events.

例如,一个新闻应用程序可以使用一个片段显示左边的文章列表,另一个片段来显示两个片段的一篇文章出现在一个活动,肩并肩,每个片段都有自己的生命周期回调方法和处理自己的用户输入事件。

 Thus, instead of using one activity to selectan article and another activity to read the article, the user can select anarticle and read it all within the same activity, as illustrated in the tabletlayout in figure 1.

因此,而不是使用一个活动来选择一篇文章,另一个活动来读这篇文章,用户可以选择一篇文章和阅读它在相同的活动,如平板电脑布局如图1所示

You should design eachfragment as a modular and reusable activity component.

你应该设计每个片段作为模块化和可重用的活动组件。

That is, because eachfragment defines its own layout and its own behavior with its own lifecyclecallbacks, you can include one fragment in multiple activities, so you shoulddesign for reuse and avoid directly manipulating one fragment from anotherfragment.

因为每个片段定义了它自己的布局和自己的行为与自己的生命周期回调,可以包括一个片段在多个活动,所以你应该设计重用,避免直接操纵一个片段来自另一个片段。

This is especiallyimportant because a modular fragment allows you to change your fragmentcombinations for different screen sizes.

这一点尤其重要,因为一个模块化的片段让你改变你的片段组合不同的屏幕尺寸。


后面还有很多页就不一一列举,!!

下载doc看更多的内容!

http://download.csdn.net/detail/qq_34900897/9826575


0 0
原创粉丝点击