当前位置:网站首页>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
边栏推荐
猜你喜欢

【Redis】一气呵成,带你了解Redis安装与连接

【无标题】

shardingSphere
![[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order](/img/87/07783593dbabcf29700fa207ecda08.png)
[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order

Differential: definition of total differential, partial derivative, gradient

CPU设计实战-第四章实践任务一简单CPU参考设计调试

【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】

Mavros sends a custom topic message to Px4

01 NumPy介绍

Field agricultural irrigation system
随机推荐
P4 installation bmv2 detailed tutorial
网关gateway-88
毕业论文中word的使用1-代码域标公式
seaborn clustermap矩阵添加颜色块
Codeworks round 803 (Div. 2) VP supplement
Why are some Wills made by husband and wife invalid
一套十万级TPS的IM综合消息系统的架构实践与思考
CPU design practice - Chapter 4 practical tasks - simple CPU reference design and debugging
2022.6.30 省赛+蓝桥国赛记录
Connect timed out of database connection
谈谈数字化转型的几个关键问题
機動目標跟踪——當前統計模型(CS模型)擴展卡爾曼濾波/無迹卡爾曼濾波 matlab實現
Stack implementation calculator
[深度剖析C语言] —— 数据在内存中的存储
深度学习训练样本扩增同时修改标签名称
To prevent "activation" photos from being muddled through, databao "live detection + face recognition" makes face brushing safer
Provincial election + noi Part VI skills and ideas
01 numpy introduction
[no title] free test questions for constructor municipal direction general foundation (constructor) and theoretical test for constructor municipal direction general foundation (constructor) in 2022
軟鍵盤高度報錯