当前位置:网站首页>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
边栏推荐
- Intelligent constant pressure irrigation system
- OJ input and output exercise
- 2022.6.30 省赛+蓝桥国赛记录
- Why are some Wills made by husband and wife invalid
- CPU设计实战-第四章实践任务一简单CPU参考设计调试
- 华为机试真题专栏订阅指引
- Luogu p1088 [noip2004 popularization group] Martians
- Intelligent water and fertilizer integrated control system
- To prevent "activation" photos from being muddled through, databao "live detection + face recognition" makes face brushing safer
- 2022 Chinese cook (technician) simulation test and Chinese cook (technician) practice test video
猜你喜欢

毕业论文中word的使用1-代码域标公式

Huawei machine test questions column subscription Guide
![[staff] high and low octave mark (the notes in the high octave mark | mark range are increased by one octave as a whole | low octave mark | mark range are decreased by one octave as a whole)](/img/ff/ebd936eaa6e57b1eabb691b0642957.jpg)
[staff] high and low octave mark (the notes in the high octave mark | mark range are increased by one octave as a whole | low octave mark | mark range are decreased by one octave as a whole)
![Thread safety analysis of [concurrent programming JUC] variables](/img/f9/a3604bec6f7e5317dd2c578da73018.jpg)
Thread safety analysis of [concurrent programming JUC] variables

华为机试真题专栏订阅指引

C basic knowledge review (Part 4 of 4)

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

CPU設計實戰-第四章實踐任務一簡單CPU參考設計調試

网关gateway-88

Learn the knowledge you need to know about the communication protocol I2C bus
随机推荐
机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现
empirical study and case study
Review of week 280 of leetcode
Adding color blocks to Seaborn clustermap matrix
使用beef劫持用户浏览器
Soft keyboard height error
[detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]
2022 examination summary of quality controller civil engineering direction post skills (quality controller) and reexamination examination of quality controller civil engineering direction post skills
Codeworks round 803 (Div. 2) VP supplement
Provincial election + noi Part VI skills and ideas
Provincial election + noi part I dynamic planning DP
Programmer's regimen
Leetcode t39: combined sum
Agrometeorological environment monitoring system
Conception et mise en service du processeur - chapitre 4 tâches pratiques
基于Gazebo的无人机管道检测
Stack implementation calculator
Tita OKR: a dashboard to master the big picture
Anddroid text to speech TTS implementation
7-26 word length (input and output in the loop)