Android UI rendering

1. overdraw optimization

What is overdraw?

Overdraw (overdraw) describes a pixel on the screen is drawn several times within the same time frame. In the multi-layered overlapping UI structure which, if not visible UI are doing the drawing operation will result in some pixel area is drawn several times. This will waste a lot of CPU and GPU resources.

From the developer can set options to see overdraw areas, red is the most serious overdraw areas.

Optimization Method:

1. 移除布局中多余的背景 
2. 减少层级嵌套,使用约束布局
3. 减少透明度使用

###### custom view onDraw caused by over-exaggerated, you can use canvas.clipRect methods to be tailored canvas. Or use canvas.quickReject.

2. Other UI optimization

Multi-use padding instead of margin

Use merge can reduce hierarchy.

Use ViewStub, lazy loading, no time must not be loaded

Minimize the use of bitmap, more use of shape like

16ms problem

Mainstream refresh rate is 60 times / second, converted out it is 16ms refresh. If this time is greater than the human eye will feel Caton. But 16ms is not the time to draw, draw time left to actually be less than this, as far as possible for the little custom view, the implementation of long onDraw to.

Note: When drawing View contents of any changes that they will need to re-create DisplayList, rendering DisplayList, updates to the screen a series of first-class operation. The performance properties of the process depends on the complexity of your View, status changes and execution performance of the rendering pipeline View. For example, suppose the size of a Button needs to be increased to double the current size before increasing Button, need to be recalculated and the placement of other sub-View by the parent View. View modify the size of the operation will trigger the re-calculation of the size of the entire HierarcyView. If it is modified View location HierarchView recalculated View other locations will be triggered. If the layout is very complex, it will be very easy to cause serious performance problems.

Use vector graphics instead of jpg, png

Published 17 original articles · won praise 12 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_24295537/article/details/104984171