Android Custom View Basics: Introduction ViewRoot, DecorView & Window is

944365-207a738cb165a2da.png

Foreword

  • Custom View is the principle of Android developers need to know basis, before Understanding Custom View, you need to have some knowledge reserves.
  • Today, it will be fully resolved on the basis of Custom View: ViewRoot, DecorView & Window , hope you like it.

table of Contents

944365-d0354efb1a6ddfcf.png
schematic diagram

1. ViewRoot

1.1 Introduction

944365-b46c98a1c44620c7.png
schematic diagram

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 Definitions

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

2.2 Role

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

2.3 Special Note

Containing a vertical direction LinearLayout, divided into two parts:

  1. = On the title bar (titlebar)
  2. Under Column = content (content)
944365-4923b6377b032256.png
schematic diagram

In Activitythrough setContentView()into the layout file set is actually being added to the contents of the column, becoming the only son View = id for the content of FrameLayoutthe

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

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

3. Window

944365-3d680d03d1fd9737
Brief introduction

4. Activity

944365-dd1d1de1f3eb9bb5
schematic diagram

5. The relationship between

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

5.1 summary

944365-aeeb7d69afb2cd63
schematic diagram

The relationship between 5.2

944365-34992eb46bdf93e7.png
schematic diagram

6. Summary


Please thumbs up! Because you agree / encouragement is the greatest power of my writing!

Read related articles
Android event distribution mechanism to explain: the history of the most comprehensive and easy to understand
Android development: the most comprehensive and understandable Android screen adaptation solutions

Android Development: the most complete history of Android push messaging solution for
Android developers: the most comprehensive and understandable Detailed Webview
Android development: JSON profile and most comprehensive analytical method!
Android four major components: Service service history of the most comprehensive analysis of
Android four components : BroadcastReceiver history of the most comprehensive analysis


Welcome concern Carson_Ho Jane book!

From time to time to share about Android development dry goods, the pursuit of short, flat, fast , but does not lack depth .

944365-9b76fa3c52d478a7.png

Reproduced in: https: //www.jianshu.com/p/28d396a0f05f

Guess you like

Origin blog.csdn.net/weixin_34411563/article/details/91198822