[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
[U8] Android UI Framework
All user interface elements in an Android app are built using a hierarchy of View and ViewGroup objects. A View is an object that draws something on the screen that the user can interact with (usually UI widgets such as buttons or text fields). A ViewGroup is an invisible view container that holds other child View (and ViewGroup) objects in order to define the layout of the interface (such as in a grid or a vertical list).
Android provides a collection of both View and ViewGroup subclasses that offer you common input controls (such as buttons and text fields) and various layout models (such as a linear or relative layout).
UI Layout
The user interface for each component of an app is defined using a hierarchy of View and ViewGroup objects, as shown in the image. Each view group is an invisible container that organizes child views, while the child views may be input controls or other widgets that draw some part of the UI. This hierarchy tree can be as simple or complex as necessary (but simplicity is best for performance).
External Representation
To declare a layout, you can instantiate View objects in code and start building a tree, but the preferred way to define a layout is with an XML file. XML offers a human-readable hierarchical structure for the layout, similar to HTML.
The name of an XML element for a view is respective to the Android class it represents (a subclass of View and ViewGroup). So a element creates a TextView widget in your UI, and a element creates a LinearLayout view group (Layouts are subclasses of ViewGroup).
When a layout resource is loaded in an app, Android initializes each node of the layout into a runtime object you can use to define additional behaviors, query the object state, or modify the layout.
In Android, declaring the UI layout in XML rather than runtime code is especially important so you can create different layouts for different screen sizes.
Android UI Elements
The UI doesn't need to be built using View and ViewGroup objects. Android provides several app components that offer a standard UI layout for which you just define the content. These UI components have a unique set of APIs that are described in their respective documents, such as Action Bar, Dialogs, and Status Notifications.
For a detail of Android UI elements see this page