Android中View绘制过程(二) Activity的decorView , Window ,ViewRooImpl 分别什么时候创建

源码读起来老是容易忘掉,备忘一下记号。decorView , Window 是通过ViewRooImp来建立联系的,那么他们分别的创建时间点是在哪?看了这个忘了那个。。。。

ActivityThread.java 中

performLaunchActivity() 创建Activity()

activity = mInstrumentation.newActivity(
                    cl, component.getClassName(), r.intent);
activity调用Activity中的attach创建Window

mWindow = new PhoneWindow(this, window);
handleResumeActivity()调用Phonewindow 的getDecorView()创建DecorView()
View decor = r.window.getDecorView();

  @Override
    public final View getDecorView() {
        if (mDecor == null || mForceDecorInstall) {
            installDecor();
        }
        return mDecor;
    }
installDecor中newDecorView

继续调用addview

 wm.addView(decor, l);


WindowManagerGlobal.java 中的addView创建

root = new ViewRootImpl(view.getContext(), display);

mViews.add(view);
            mRoots.add(root);
            mParams.add(wparams);

添加到所有根列表,1)mViews所有DecorView  2)mRoots所有ViewRootImpl 3)DecorView的WindowParam。 便于之后的查找删除更新。

ViewRootImpl.java

创建完之后setView()

root.setView(view, wparams, panelParentView);

在这里会调用绘制流程。

// Schedule the first layout -before- adding to the window
                // manager, to make sure we do the relayout before receiving
                // any other events from the system.
                requestLayout();

这里说明,第一次添加Window。

进入到performTraversals()

res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes,
                            getHostVisibility(), mDisplay.getDisplayId(),
                            mAttachInfo.mContentInsets, mAttachInfo.mStableInsets,
                            mAttachInfo.mOutsets, mInputChannel);


这其中的参数mWindow 是一个Stub也就是个Binder,类中持用ViewRooImpl的弱引用。

mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor);

添加到界面显示,在Session.java

@Override
    public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
            int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets,
            Rect outOutsets, InputChannel outInputChannel) {
        return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
                outContentInsets, outStableInsets, outOutsets, outInputChannel);
    }


之后调用一系列将Window添加到显示的界面,还有一些界面相关的类,和底层显示相关的就没有看了,书上也没有介绍,和应用开发联系不大。


综上来看,ViewRootImple,连接了Window,DecorView,并且使用Binder的调用将Window添加,至于如何添加不再关注,因为有很多底层的绘制和类要分析且没有必要。




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值