Android View Drawing Process Explained

The process of drawing Android Views generally involves the following steps:

  1. Request for drawing: When a View needs to be drawn, it will call the invalidate() method to trigger the redraw operation. In the invalidate() method, the ViewRootImpl’s scheduleTraversals() method will be called, which will ultimately call the scheduleTraversals() method to begin the drawing operation.
  2. Measuring Size: Before performing drawing operations, it is necessary to measure the View to determine its size and position. The measure() method is called first to measure the size of the View, which includes measuring both the size of the View itself and its child Views.
  3. Layout position: After measurement is completed, the layout() method will be called to determine the layout position of the View, placing it in the specified position within the parent container.
  4. Drawing content: Ultimately, the draw() method is called to carry out the actual drawing process. Within the draw() method, the onDraw() method of the View is invoked to draw the content of the View, as well as the content of its child Views.
  5. Drawing completed: after the drawing operation is finished, the finishTraversal() method of ViewRootImpl is called to complete the entire drawing process and display the drawing result on the screen.

In general, the process of drawing an Android View includes measuring size, laying out the position, and drawing the content, ultimately completing the entire drawing operation and displaying the result on the screen.

bannerAds