On Android ViewRoot, DecorView & Window

Brief introduction

Here Insert Picture Description

  • DecorView as the topmost Window View entire interface.
  • DecorView only one child is LinearLayout. Representative of the Window interface, includes the notification bar, title bar, display the contents of three bar area.
  • There are two LinearLayout FrameLayout children.
    • (20) for the title bar display. Only a TextView display applications
    • (21) for the content bar display. It is the setContentView () method of loading a layout interface, added thereto.

table of Contents

Here Insert Picture Description

1, VeiwRoot

1.1 Introduction

Here Insert Picture Description

1.2, special attention

// 在主线程中,Activity对象被创建后:
// 1. 自动将DecorView添加到Window中 & 创建ViewRootImpll对象
root = new ViewRootImpl(view.getContent(),display);

// 3. 将ViewRootImpll对象与DecorView建立关联
root.setView(view,wparams,panelParentView)

2、DecorView

2.1, the definition of

Top View, i.e. the root node of the tree view Android; FrameLayout also the subclass.

2.2 Role

Load & display layout. Event View layers have to go through DecorView, and then passed to the View.

2.3 Special Note

Containing a vertical direction LinearLayout, divided into two parts:

  • = On the title bar (titlebar)
  • Under Column = content (content)
    Here Insert Picture Description

In Activitythrough setContentView()into the layout file set is actually being added to the contents of the column, becoming the only child View = idto contentthe FrameLayoutmiddle.

注:获取setContentView()设置的View代码如下:

// 在代码中可通过content得到对应加载的布局

// 1. 得到content
ViewGroup content = (ViewGroup)findViewById(android.R.id.content);
// 2. 得到设置的View
ViewGroup rootView = (ViewGroup) content.getChildAt(0);

3、Window

Here Insert Picture Description

4、Activity

Here Insert Picture Description

5, the relationship between

Relations ViewRoot, DecorView, Window and Activity is very important.

5.1 summary

Here Insert Picture Description

Relations between 5.2, the

Here Insert Picture Description

Published 100 original articles · won praise 45 · views 640 000 +

Guess you like

Origin blog.csdn.net/wangzhongshun/article/details/98783143