Android Screen element hierarchy

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/hpoi/article/details/4629717

Android Screen element hierarchy

Android.app.Activity
For an Android application, the Android.app.Activity class instance is one of the most basic functional units. An activity instance can do a lot of things, but it can't be displayed on the screen itself, but with the help of ViewGroup and view, these are the two most basic user interface expression units on the Android platform.


Android.view.ViewGroup


ViewGroup is a special view class that inherits from Android.view.View. Its function is to load and manage the next layer of view objects and ViewGroup objects. ViewGroup is the base class for layout Manager and view container.
ViewGroup, a nested class viewgroup.layoutparams is also defined. This class defines a display object's location, size, and so on, and the view tells the parent how they will be placed through these property values in Layoutparams.


Here, some of the main layout classes that inherit from ViewGroup are as follows:
1, Framelayout: The simplest of a layout object. It displays only one display object. All display objects will be pinned to the upper-left corner of the screen and cannot be assigned a position. However, multiple display objects are allowed, but the latter will be overwritten directly above the previous one, blocking the previous part or all (unless the latter one is transparent).
2. LinearLayout: Arranges the display objects in a single direction, as shown vertically, with only one column in the layout manager, or one row in the layout manager if displayed horizontally. It can also set the display scale for individual display objects.
3, Tablelayout: The Display object is laid out in a table with any row and column, each display object is assigned to its own cell, but the cell's border line is not visible.
4, Absolutelayout: Allow coordinates, specify the location of the display object, the upper left corner of the coordinates of (0, 0), downward and to the right, the coordinate value is larger. This layout manager is dead due to the location of the display object, so on different devices, it is possible that the final display effect is inconsistent.
5, Relativelayout: Allows layout by specifying the relative position of the display object relative to other display objects or parent objects. A button can be placed on the right side of another button, or it can be placed in the center of the layout manager.
In Android, there are a lot of layout managers, not listed here, developers can according to actual needs, choose the appropriate layout manager.

Android.view.View

View is the base class for all view classes, and a view typically occupies a rectangular area on the screen and is responsible for drawing and event processing. View is the base class for all form parts that are serviced for the form part, where the form part is the UI control, such as a button or text box. Android has provided us with a range of standard UI controls for direct use, and we can implement our custom UI controls by inheriting from the view class or view subclasses.
To customize our own UI controls, you need to overload some of the methods in the view class, and the following table lists the methods that the view provides for overloading, which do not have to be overloaded, but at least implement the OnDraw (Android.graphics.Canvas) method.

When you add a visible view for a activty and run this activty, Android typically automatically triggers the view's related events in the following order

Onattachedtowindow
Onmeasure
Onsizechanged
OnLayout
OnDraw

For a screen in an Android app, its screen elements are described in a hierarchical structure. To bind a screen element hierarchy to a screen, the activity invokes its Setcontentview () method and passes in the root node reference of the hierarchy tree. When activity is activated and gets focus, the system notifies the activity and requests the root node to compute and draw the tree, and the root node requests its child nodes to draw themselves.


The ViewGroup node on each tree is responsible for drawing its child nodes. ViewGroup calculates its effective space, layouts all the child display objects, and eventually calls all the child display objects of the draw () method to draw the display object. Each child display object can request their size and position in the layout to the parent object, but ultimately the size and position of each child display object is the parent object.

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.