在activity的setContentView方法会使用layoutId作为参数实例化一个PhoneWindow。
在PhoneWindow里面也有一个setContentView方法,里面有一个mContentParent,它就是我们布局layout的父布局,是一个ViewGroup,mContentParent就是mDecor本身或者mDecor的一个子类。它在setContentView里面实现如下。



mContentParent是使用DecorView对象来实例化的:mContentParent = generateLayout(mDecor);
mDecor的实现:


DecorView是PhoneWindow的一个内部类。
DecorView是一个FrameLayout,PhoneWindow使用DecorView来创造一个layout,如果没有actionbar,那么整个DecorView只有一个子View,即mContentParent,而mContentParent包含了我们自定义的layout。如下图:

总结整个流程Window的实现类——>PhoneWindow。1 新建窗口就是实例化一个PhoneWindow。2 PhoneWindow实例化就是创建一个DecorView。3 DecorView承载Actionbar和mContentParent。4 mContentparent承载着自定义的xml的layout。
网友评论