Activity 中的root view 添加子view的大致过程

来源:互联网 发布:辐射4派普优化 编辑:程序博客网 时间:2024/05/19 14:53


Activity是要显示界面给用户的,跟布局文件中的子View是如何添加到root view中的呢,

下面总结了大致过程,详细内容可以一一分析源码(需要查看Activity,PhoneWindow,LayoutInflater,ViewGroup等),这里不做详细介绍:

1.Activity调用setContentView(int layoutId)
2.调用phoneWindow的setCotentView方法
3.在LayoutInflater中加载layoutId视图(inflate方法),利用parser将布局树解析出来
4.利用LayoutInflater的createViewFromTag将root布局初始化(即parent view)
5.同理createViewFromTag创建子view并利用rInflate方法将子view添加到parent中 (addView方法)
6.在addView方法中利用ViewGroup的addInArray方法改变ViewGroup自己的childCount 和 View 数组(将子View添加到 View[] child)
0 0