当前位置:网站首页>View drawing process analysis
View drawing process analysis
2022-07-01 08:30:00 【Hatshepsut】
setContentView() What did you do
We know that onCreate() In the method setContentView() The method is to xml The file resolves to DecorView On , that DecorView When was it displayed on the screen ?

We all know activity In the life cycle of onResume() A lot of work , and onResume() As shown in the figure above . stay ActivityThread in ,handleResumeActivity() Methods not only call performActivity() Method is finally implemented on onResume() Method call , The following operations are also carried out .

and ViewManger It's an interface , The real thing is WindowMangerImpl

The real call is WindowManagerGlobal Of addView() Method


Method ViewRootImpl
mViews.add(view); //DecorView
mRoots.add(root); //ViewRootImpl
mParams.add(wparams) //WindowManager.LayoutParams
root.setView(view, wparams, panelParentView);// take view and viewRootImpl Binding
Go find ViewRootImpl Of setView() Method , The most important thing is the internal call requestLayout() Method

stay requestLayout() In the method , First of all be checkThread() Check whether the current thread is the main thread , And then execute scheduleTraversals() Method for real rendering .


scheduleTraversals() Pass through mTraversalRunable perform doTraversal() Method

Final execution to performTraversals() Method , draw view Is executed in this method .

performTraversals() The method is very long. , Did a lot of things
1. windowSizeMayChange |= measureHierarchy(host, lp, res, desiredWindowWidth, desiredWindowHeight); Notes also explain , Is to ask for the desired size , That is, the predicted quantity

Only wrap_content The situation that needs to be negotiated
a. First, through res.getValue Give an initial value to measure
b.performMeasure()
c.if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0)
If the measurement result is satisfactory , Is set to true
d. If not satisfied if Conditions , The modified baseSize,
baseSize = (baseSize+desiredWindowWidth)/2,
Re engage performMeasure()
e. If not satisfied , The window width and height are assigned to , For the third time performMeasure()


If windowSizeMayChange = true, It means that measurement is still needed
2. relayoutResult = relayoutWindow(params, viewVisibility, insetsPending);// Layout window Actually WMS In the called

3.performMeasure(childWidthMeasureSpec,childHeightMeasureSpec);// Measurement of the number of controls ( At most 4 Time performMeasure())


perform view Of itself measure() Method ,measure() Methods must call setMesureDemension() Method

4.performLayout(lp,mWidth,mHeight)

Allied , call view Of layout() Method

Can be done layoutChange Listening in , And learn about the changes
If it is view, You need to add your own padding, If it's a container , You need to add Margin
5.performDraw();// draw

performDraw() Method is called internally draw()

scrollToRectOrFocus(null, false) Calculate scrolling , Such as the pop-up of the keyboard ?
There are two cases of drawing : Hardware acceleration or Software acceleration

Software and hardware drawing process 、 difference ? To be added Better hardware rendering ( The software drawing will draw everything )
Whatever it is , Will be called view Of draw() Method , Well known ( background ,dispatchDraw() The process of ), Custom controls generally do not override this method

canvas There are also software and hardware

measure() Method is to measure and determine the size of the child control ,layout() In the onLayout() The method is to determine the current view Position in the parent control
stay ViewRootImpl Of setView() In the method , Other operations were also performed . The purpose is to add windows to WMS On 、

Give yourself the current view Set up parent

stay ViewRootImpl Constructor

mThread = Threag.currentThread() // Get the thread that created it
mDirty = new Rect() // Dirty areas
mAttachInfo = new View.AttachInfo() // Save some information about the current window
WindowMangerImpl determine View Which parent window does it belong to
WindowManagerGlobal Manage the entire process All window information
ViewRootImpl yes WindowManagerGlobal The actual operator of , Operate your own window
边栏推荐
- Leetcode t31: next spread
- Using settoolkit to forge sites to steal user information
- 2022 ordinary scaffolder (special type of construction work) examination question bank and the latest analysis of ordinary scaffolder (special type of construction work)
- Provincial election + noi Part III tree problems
- Burpsuite -- brute force cracking of intruder
- Yolov5 advanced 7 target tracking latest environment setup
- Leetcode T39: 组合总和
- [getting started] input n integers and output the smallest K of them
- Rumtime 1200 upgrade: London upgrade support, pledge function update and more
- Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
猜你喜欢
![[detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]](/img/0f/972cde8c749e7b53159c9d9975c9f5.png)
[detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]

Instead of houses, another kind of capital in China is rising

There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way

机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现
![[untitled]](/img/d9/5e97f2de256b9749131b5bf1437d24.png)
[untitled]

Comprehensive experiment Li

Use threejs simple Web3D effect

The era of low threshold programmers is gone forever behind the sharp increase in the number of school recruitment for Internet companies

2022.2.15

Pipeline detection of UAV Based on gazebo
随机推荐
使用threejs简单Web3D效果
Gdip - hatchbrush pattern table
[question brushing] character statistics [0]
Why are some Wills made by husband and wife invalid
OJ input and output exercise
Leetcode T39: 组合总和
When using charts to display data, the time field in the database is repeated. How to display the value at this time?
seaborn clustermap矩阵添加颜色块
数字转excel的字符串坐标
使用beef劫持用戶瀏覽器
Leetcode t34: find the first and last positions of elements in a sorted array
Programmer's regimen
There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way
Review of week 280 of leetcode
[getting started] input n integers and output the smallest K of them
leetcode T31:下一排列
Data analysis notes 11
[untitled]
XX攻击——反射型 XSS 攻击劫持用户浏览器
機動目標跟踪——當前統計模型(CS模型)擴展卡爾曼濾波/無迹卡爾曼濾波 matlab實現