当前位置:网站首页>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
边栏推荐
- 2022 Chinese cook (technician) simulation test and Chinese cook (technician) practice test video
- Leetcode T40: 组合总和II
- Set up file server Minio for quick use
- Airsim radar camera fusion to generate color point cloud
- [force deduction 10 days SQL introduction] Day10 control flow
- Huawei machine test questions column subscription Guide
- Connect timed out of database connection
- 程序员养生宝典
- Anddroid 文本合成语音TTS实现
- Manually dig XSS vulnerabilities
猜你喜欢

MATLAB小技巧(16)矩阵特征向量特征值求解一致性验证--层次分析
![[untitled]](/img/b9/6922875009c2d29224a26ed2a22b01.jpg)
[untitled]

MAVROS发送自定义话题消息给PX4

一套十万级TPS的IM综合消息系统的架构实践与思考

Suivi des cibles de manoeuvre - - mise en oeuvre du modèle statistique actuel (modèle CS) filtre Kalman étendu / filtre Kalman sans trace par MATLAB

The use of word in graduation thesis

华为机试真题专栏订阅指引
![[question brushing] character statistics [0]](/img/cc/f5aaecd920c502180303d92447e54f.png)
[question brushing] character statistics [0]

Maneuvering target tracking -- current statistical model (CS model) extended Kalman filter / unscented Kalman filter matlab implementation
![[dynamic planning] p1020 missile interception (variant of the longest increasing subsequence)](/img/3e/75a1152f9cdf63c6779fdadec702a0.jpg)
[dynamic planning] p1020 missile interception (variant of the longest increasing subsequence)
随机推荐
[force deduction 10 days SQL introduction] Day9 control flow
Tita OKR: a dashboard to master the big picture
To prevent "activation" photos from being muddled through, databao "live detection + face recognition" makes face brushing safer
How to use OKR as the leadership framework of marketing department
CPU设计实战-第四章实践任务一简单CPU参考设计调试
7-26 word length (input and output in the loop)
Stack implementation calculator
Gateway-88
Luogu p1088 [noip2004 popularization group] Martians
[force deduction 10 days SQL introduction] Day10 control flow
[深度剖析C语言] —— 数据在内存中的存储
Precautions and skills in using regular expressions in golang
Gdip - hatchbrush pattern table
The data analyst will be ruined without project experience. These 8 project resources will not be taken away
Intelligent constant pressure irrigation system
Uni hot update
基于Gazebo的无人机管道检测
Provincial selection + noi Part II string
[Yu Yue education] Shandong Vocational College talking about railway reference materials
[untitled]