Adroid UI Interface Drawing principle Analysis

Source: Internet
Author: User

In the development of Android app, the UI is very important. However, the Android UI controls provided by Google are sufficient for the general development of the app, but need to be

To do some complicated UI, then you need to customize the UI control yourself. When it comes to customizing UI controls, you must first understand the Adroid UI drawing principle, Android

whether it is a Google-provided Android control or a control that is defined by itself, the device needs to draw the UI controls on the phone. The following Adroid UI interface, based on what you know, paints

System principle for Analysis:

Adroid Interface Drawing Implementation
The view class contains surface (variable name msurface). Surface contains Compatiblecanvas (variable name Mcanvas). Compatiblecanvas is inherited to Canval (Java.awt.Canval), which contains a matrix object, the matrices (variable name Morigmatrix). Matrix is a piece of memory area, for view

Various painting operations are saved in this memory.


Each surface usually corresponds to two buffer, a front buffer, and a back buffer. The back buffer is the one that corresponds to the canvas drawing.

Bitmap (research Android_view_surface.cpp::lockcanvas). Therefore, the painting is always on the back buffer and needs to be updated, then the back buffer and

Front buffer interchange.
Each surface also corresponds to a layer, and Surfaceflinger is responsible for drawing the front buffer composition (composite) of each layer onto the screen.
In terms of user interface, the main performance tasks are implemented by the various inheriting classes of view. The inheritance relationship of the view class.
When the user requests the draw call invalidate (), this function finds the current view or ViewGroup Parentview and calls the parent view's Invalidatechild (this, R). Invalidatechild calls the parent view's invalidatechildinparent () so that the layer is called to the upper view until it is called to the root view viewroot. Viewroot Invalidatechildinparent calls Invalidatechild, and then sends a message for Viewroot to draw. The drawing code calls Performtraversals () in case do_traversal in Handlemessage ().
Then call the draw () function of the next level view. The draw function calls the following functions in turn:
Background.draw (Canvas)
OnDraw (Canvas)
Dispatchdraw (Canvas)
Ondrawscrollbars (Canvas)
The Drawchild function is called in the Dispatchdraw of ViewGroup. Drawchild calls the child class's draw () or Dispatchdraw (canvas) According to the private flag bit mprivateflags of the child view. This allows the layers to be drawn downward until the most basic view. The Dispatchdraw of view is an abstract function that concludes the drawing process. Finally Viewroot calls the Nativeshowfps (canvas, now-sdrawtime) function to pass the drawing result canvas to the local strata for display.

Adroid UI Interface Drawing principle Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.