Getting Started with Android's zero-single-row development diary (13)--android Control parsing

Source: Internet
Author: User

Android controls are derived from the Android.view.View class, and a large number of system controls are defined in the Android.widget package for developers to use, and developers can derive custom controls from the view class and its subclasses.

First, the control structure of Android

Android has a class of important controls, called container controls, that derive from view's subclass Android.view.ViewGroup. Each container control can exist as a parent control, containing several child controls, each of which occupies a single area of its parent control, which is managed and dominated by the parent control.

The relationship between controls in the interface is visually extremely complex, so Android abstracts the links between control objects into a tree structure, simplifying the relationship between controls--each control is controlled only by its parent control, not by other controls. In order to guarantee the integrity of the control, Android adds a unified interactive event management object to the Viewparent, which can schedule the change of the control tree as a whole and avoid the local communication between the control objects, thus greatly reducing the coupling between the control objects.

In Android controls, interactive events are propagated from top to bottom along the control tree. After the parent control accepts the interaction event, it first judges the event's target control object and, if it needs it, intercepts the event for processing, or attempts to distribute the event down to the corresponding child control, and recursively propagates the event downward until the event is processed or ignored. In Android, view defines a series of event functions to receive and process various kinds of interactive events, such as the View.onkeydown function can receive the user's key operation, Ontouchevent can get the user touch screen related events, and so on. The child controls of each view class can overload these functions to handle the events that they require.

Second, the control properties of Android

Each Android control has a certain property that represents the basic characteristics of the control object. These properties are defined in the view class.

    1. identity

    2. size
    3. visibility is not visible, the position of the control does not change, and when the control is in a vanishing state, it no longer occupies any of the interface areas, and its position is replaced by other controls.
    4. Focus

Third, the Windows mechanism of Android

The so-called window mechanism, refers to the Android to take a window-based registration of implementation mode, the user interface with the interaction of the transfer to the corresponding control. The use of interface development in C + + and Java may be more familiar.

At the heart of the window mechanism is the Window Management Service (Windowmanagerservice), which is one of the core services of the Android system and runs in a separate thread in the core process of the system. It is responsible for managing the control tree of the interactive interface and translating the user actions into interactive events to the current interface.

  1. interface components and Windows
    Interface components are the most important interactive unit in Android, and each interface component has a Android.view.Window object. Each Window object is responsible for constructing and managing a control tree, which constructs a corresponding Viewroot object for that control tree to establish two-way communication with the window Management service. The interface component's interface is mainly composed of the title area and the content area. The format of the title is relatively fixed, usually by the title text, progress bar and component icons and other elements, developers can use the Settitle method to change the content of the title. Content areas can be set by Setcontentview functions or by customizing them. Of course, developers tend not to be content with such a basic interface framework, so Android offers a number of interfaces to help developers break through the basic interface styles.
  2. dialog box
    The dialog box is also an important interaction unit that needs to be hosted in one of the interface components. Compared with interface components, dialog boxes are constructed with lighter weight, simpler life cycles, and faster data transfer. Therefore, it is often used as a temporary auxiliary interaction object to prompt the relevant information to the user.
    // constructs and presents a dialog object in the interface component New Alertdialog.bulider (this)      . Settitle ("dialog box title")  // Set caption      . Setmessage ("dialog box contents")// set prompt information      . Setpositivebutton ("Off",new  Onclicklistener () {       // related processing }). Show ();

    Its content area is used to set prompt information or to accept user input information. The Alertdialog.builder object provides a number of convenient interfaces for developers to use, such as text messages that can be set via AlertDialog.Bulider.setMessage, or AlertDialog.Bulider.setItems function settings Select a list or you can customize the style of the content area by AlertDialog.Bulider.setView.
    In the interface component, you can use the Activity.showdialog function to pop up the specified dialog object, and the developer needs to construct it in the Activity.oncreatedialog function. Once the dialog box is constructed, it is cached. Developers can use the Activity.dismissdialog function to eliminate the dialog box, you can delete the cached dialog box object through the Activity.removedialog function. The Activity.onpreparedialog function is called every time the dialog is rendered, and the developer can reload the function to dynamically change the contents of the dialog object.

  3. Pop-up window
    An object derived from Android.widget.Popup.Window. The function is also used in the interface component to construct a temporary interface. from the point of view of use, Popwindow does not pop up from the fixed position of the screen like a dialog box, but relies on the position of the stroke control object. Popwindow's display box functionality is centered on it as an extended interactive interface for the stroke control to enhance the functionality of the control.
    such as: AutoComplete text Control Android.widget.AutoCompleteTextView is an application instance of Popwindow. It has a text input control that is combined with the popwindow that binds it.

Iv. Basic Android controls

Controls are the basic units of the build interface. To help build a better interface, Android provides a number of basic controls. For developers, it is only by understanding the implementation characteristics and usage of these controls that the development of interactive interfaces can be made faster and better. So next, I'll give you an introduction to the more important controls in Android, with a simple code of operation.

========================================

Cpacm
Source: (http://www.cnblogs.com/cpacm/p/3954139.html)

Android Zero-single-row development Journal (13)--android Control parsing

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.