1.1.2 Activity的UI架构及创建流程

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>
    

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中

  1. 实现类是PhoneWindow ↩︎

  2. DecorView是PhoneWindow的内部类,DecorView是FrameLayout的子类。从DecorView开始都是继承自View的,所以视图的绘制从DecorView开始一次递归 (ViewGroup -> View) 调用 measure、layout、draw ↩︎

  3. mContentParent就是ID为content的View,即ContentView ↩︎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

氦客

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值