界面第一课:Fragment
A Fragment is a piece of an application's user interface or behavior that can be placed in an Activity. Interaction with fragments is done through FragmentManager, which can be obtained via Activity.getFragmentManager() and Fragment.getFragmentManager().
The Fragment class can be used many ways to achieve a wide variety of results. In its core, it represents a particular operation or interface that is running within a larger Activity. A Fragment is closely tied to the Activity it is in, and can not be used apart from one. Though Fragment defines its own lifecycle, that lifecycle is dependent on its activity: if the activity is stopped, no fragments inside of it can be started; when the activity is destroyed, all fragments will be destroyed.
All subclasses of Fragment must include a public empty constructor. The framework will often re-instantiate a fragment class when needed, in particular during state restore, and needs to be able to find this constructor to instantiate it. If the empty constructor is not available, a runtime exception will occur in some cases during state restore.
Fragment 可以称作是软件界面的一个小片段或是可以放在一个活动里的行为。Fragment的交互通过fragment管理器,可以通过Activity.getFragmentManager()和Fragment.getFragmentManager()这两个方法实现。
Fragment这个类可以使用许多方法来获得各种各样的结果。在其核心,它代表了一个大型活动中的一个特定的操作或接口。一个片段和活动密切相关,依赖于活动而存在。尽管片段定义了它自己的生命周期,生命周期取决于其活动:如果活动停止,所有碎片将停止;当活动被摧毁,所有片段将被摧毁。
所有片段的子类必须包括一个公共空构造函数。框架需要时往往会重新实例化一个片段类,尤其是状态恢复时,需要能够找到这个构造函数实例化它。如果空构造函数不可用,在某些情况下状态恢复时会发生异常。
Fragment作为应用界面的一部分或行为,可通过FragmentManager进行交互。每个Fragment代表一个操作或接口,与活动紧密相关,其生命周期受活动控制。所有Fragment子类需包含公共空构造函数以确保框架正确实例化。

被折叠的 条评论
为什么被折叠?



