Android Window Mechanism Analysis-UI Management System

Source: Internet
Author: User

Activity can be seen as a human-machine interface of the entire android system. It provides a window to draw the UI. When every activity is started, we need to set a content view for it, as the UI content presented by the activity, this process is implemented through the setcontentview () method.

As we all know, the concept of view is enhanced in the Android system, mainly reflected in the management of view. View in Android exists in two forms, and a single view and a viewgroup composed of multiple views. Content view exists in the form of viewgroup. That is to say, you can add multiple views in an activity window, thus realizing diversified UI of the android window system. Content set for the activity window at activity startup
View is parsed from an XML file. How does Android manage this contentview? What is its internal implementation logic?

Before the analysis, first give a hierarchical relationship between the window of the activity and the view system. This hierarchical relationship is the situation after the activity sets the contentview.

For example.



The following describes the meanings and functions of each level.

1.1 phonewindow

Phonewindow is the most basic Window System in Android. Each activity creates a phonewindow object, which is an interface for interaction between the activity and the entire view system.


1.2 decorview

Decorview is the ancestor of all views of the current activity. It does not present anything to users. It mainly has the following functions and may not be complete:

A. External events such as key, touch, and trackball distributed by dispatch viewroot;

B. decorview has a direct sub-view, which is called system layout. it contains the current UI style, such as whether to include the title or process bar. These attributes can be called window decorations.

C. As a bridge between phonewindow and viewroot, viewroot sets window properties through decorview.


1.3 system layout

Currently, Android has preset several UI styles based on user requirements, and uses phonewindow to parse the preset layout. XML to get layout that contains different window decorations. We call it system layout. we add this system layout to decorview. Currently, Android provides eight types of system layout, for example.

You can use the phonewindow method requestfeature () to set the default style. Note that this method must be called before the setcontentview () method is called.


1.4 content parent

Content parent: The viewgroup object is the correct contentview parent. Our contentview finally finds the host, which corresponds to a framelayout with the ID "content" in system layout. This framelayout object includes the layout of our activity (each system layout will have a framelayout with the ID of "content ).



1.5 activity Layout

This activitylayout is the contentview we need to set to the window. Now we find that its position is very low, and this part is the UI part of the interaction with the user, the preceding layers cannot respond to and complete the user input expectations.

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.