Analysis of Adroid UI Rendering Principle, adroidui

Source: Internet
Author: User

Analysis of Adroid UI Rendering Principle, adroidui

In the development of Android apps, UI display is very important. However, the Android UI control provided by Google can meet the needs of normal APP development.

To do some complex UI, You need to customize the UI control by yourself. Speaking of custom UI controls, you must first understand the Adroid UI Rendering Principle.

Whether it is an Android control provided by Google or a custom control, You need to draw the UI control on your mobile phone. The following is an example of the Adroid UI.

Analysis:

Adroid interface rendering implementation
The View class contains the Surface (variable name mSurface ). The Surface contains CompatibleCanvas (variable name: mCanvas ). CompatibleCanvas inherits to Canval (java. awt. Canval), which contains a Matrix object Matrix (variable name: mOrigMatrix ). Matrix is a memory area.

Various Painting operations are stored in this memory.


Each Surface usually corresponds to two buffers, one front buffer and one back buffer. The back buffer corresponds to

Bitmap (study android_view_Surface.cpp: lockCanvas ). Therefore, the painting is always on the back buffer. When an update is required, the back buffer and

Front buffer interchange.
Each surface corresponds to another layer, and SurfaceFlinger is responsible for drawing the front buffer synthesis (composite) of each layer to the screen.
In terms of user interfaces, the main task is implemented by various inheritance classes of View. The inheritance relationship of the View class.
When the user requests to draw and calls invalidate (), this function finds the ParentView of the current View or Viewgroup and calls the invalidateChild (this, r) of the parent View ). InvalidateChild cyclically calls the invalidateChildInParent () of the parent view, so the call is made to the upstream view layer by layer until the call is made to the ViewRoot of the Root View. InvalidateChildInParent of ViewRoot calls invalidateChild and sends a message for ViewRoot to draw. The drawing code calls javasmtraversals () in case DO_TRAVERSAL of handleMessage ().
Call the draw () function of the next view. The draw function calls the following functions in sequence:
Background. draw (canvas)
OnDraw (canvas)
DispatchDraw (canvas)
OnDrawScrollBars (canvas)
The drawChild function is called in dispatchDraw of ViewGroup. DrawChild calls the draw () or dispatchDraw (canvas) of the subclass based on the private flag mPrivateFlags of the child View ). This allows you to draw down layers until the most basic View. View's dispatchDraw is an abstract function. The painting process ends here. Finally, ViewRoot calls the nativeShowFPS (canvas, now-sDrawTime) function to pass the painting result canvas to the local layer for display.

Related Article

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.