Activity的UI架构
-
每个Activity都包含一个Window对象1
-
PhoneWindw都DecorView设为整个应用窗口的根布局2
- DecorView将要显示的具体内容呈现在了PhoneWindow上。封装了一些窗体操作通用方法。
- 所有View的监听事件,都通过WindowManagerService来进行接收,并通过Activity对象来回调相应的onClickListener。
-
ContentRoot(基础布局)根据不同的主题会有不同的布局方式
- 比如最常见的TitleView和ContentView的组合
ContentRoot的布局我们以screen_simple
来举例
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:orientation="vertical"> <ViewStub android:id="@+id/action_mode_bar_stub" android:inflatedId="@+id/action_mode_bar" android:layout="@layout/action_mode_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="?attr/actionBarTheme" /> <FrameLayout android:id="@android:id/content" android:layout_width="match_parent" android:layout_height="match_parent" android:foregroundInsidePadding="false" android:foregroundGravity="fill_horizontal|top" android:foreground="?android:attr/windowContentOverlay" /> </LinearLayout>
- 比如最常见的TitleView和ContentView的组合
Activity UI架构的创建流程3
Activity.setContentView()
-> PhoneWindow.setContentView()
-> PhoneWindow.installDecor();
-> PhoneWindow.generateDecor() //1.创建DecorView
-> PhoneWindow.generateLayout(mDecor); //2.加载基础布局ViewGroup (ContentRoot)
-> requestFeature 设置主题
-> 根据不同的主题 赋值layoutResource为不同的布局
-> DecorView.onResourcesLoaded
-> 通过inflater.inflate(layoutResource)创建ContentRoot
-> 通过addView添加到DecorView中
-> mLayoutInflater.inflate(layoutResID, mContentParent); //3.将ContentView添加到基础布局中的FrameLayout中