谈谈Fragment

从Android 3.0(API11) 起,Google 支援Fragment。今天稍微说说什麽是Fragment (https://developer.android.com/guide/fragments)。

A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment. The fragment’s view hierarchy becomes part of, or attaches to, the host’s view hierarchy.

依Google Android Development 的介绍,Fragment 可以有以下的特点:

  • Fragment 代表应用 UI 的可重用部分
  • 片段定义和管理自己的布局,拥有自己的生命周期,并且可以处理自己的输入事件
  • 片段不能独立存在——它们必须由活动或另一个片段托管
  • 片段的视图层次结构成为宿主视图层次结构的一部分或附加到宿主的视图层次结构

简单看Fragment,它就是「模组化」的使用者介面,只是它可以依不同的情况使用而有不同的生命周期。

一个Activity 可以包含多个Fragment

Fragment 的生命周期可以包含有(https://developer.android.com/guide/fragments/lifecycle):
INITIALIZED: onCreate(), onCreateView(), onViewcreated()
CREATED: onViewStateRestored(); onStop(), onSaveInstanceState(), onDestroyView()
STARTED: onStart(); onPause()
RESUMED: onResume()
DESTROYED: onDestroy()


<<:  事件查看练习(一)--可忽略的错误

>>:  [Day 19] Sass - Functions

Day 30 最终章:结语与初心

各位读者大家好~我是Android工程师兼作家 小笠宏树,今天不演别人演我自己。希望大家这个系列看得...

那些被忽略但很好用的 Web API / CreateDocumentFragment

除了功能完善,有时候效能也该一并考虑。 今天要介绍的是 CreateDocumentFragmen...

Day [28] Azure 认知服务-Custom Vision 建置

Build a classifier with the Custom Vision website ...

CMM和CMMI

-CMM和CMMI成熟度级别比较 软件工程学院(SEI),1984年 软件工程学院(SEI)於19...

Day24:今天我们来聊一下Azure Sentinel中使用的关注清单

Azure Sentinel提供资料表来储存可供Kusto查询语言(KQL)查询存取的清单资料。 A...