Explanation of the android User Interface (go 1)

Source: Internet
Author: User

This section describes how to implement a basicAndroidInterface. It involves creating basic screen elements, how to define the screen in XML (definition file), use your code to generate, and perform operations on your user interfaces in different tasks.Android generates screens in three ways: xml configuration generation, user interface generation, and code generation. According to the MVC principle, the UI should be separated from the program logic. Therefore, it is highly recommended to define the UI structure in XML. In addition, it is much easier to adjust a program from one screen solution to another. Defining the UI in XML is very similar to creating a common HTML document. For example, you have the following file:
<HTML>
<Head>
<Title> page title </title>
</Head>
<Body>
The content of the Body element.
</Body>
</Html>

Just like the XML layout of Android, all elements are structured and can be expressed in a tree structure:
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout
Xmlns: Android = http://schemas.android.com/apk/res/android
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Hello World"/>
</Linearlayout>

3.2.1 layer of screen elementsThe basic function unit of an android application is an object in the activity-android. App. Activity Class. An activity can do many things, but it is not displayed on the screen. To display your activity on the screen and design its UI, you need to use view and viewgroup --AndroidThe basic user interface expression unit of the platform.
Views
A view is an object of the android. View. view basic class. It is a data structure that stores the layout and content attributes of a specific rectangle on the screen. A view object handles ranging and layout, drawing, focus conversion, scroll bars, and buttons and gestures displayed in the screen area.
As a base class, the view class serves widgets (form parts). widgets are a complete set of child classes used to draw interactive screen elements. Widgets process their own ranging and plotting, so you can use them to build your UI more quickly. Available widgets include text, edittext, inputmethod, button, radiobutton, checkbox, and scrollview .......
Viewgroups
A viewgroup isAndroid. View. viewgroup class object. As its name indicates, a viewgroup is a special view object, which is used to load and manage a group of lower-layer views and other viewgroups, viewgroup allows you to add structures to your UI and construct complex screen elements into an independent entity.
The viewgroup class serves as a base class for layout (layout). layout is a complete implementation subclass that provides a common type of screen interface. Layout allows you to build a structure for a group of views.
A tree structure Interface 
On the Android platform, you can use the view tree and viewgroup nodes to define the UI of an activity, just like the following chart. This tree can be as simple or complex as you need, and you can build it using Android pre-defined widgets and layout or your custom view type.
Example of a view and viewgroup tree:

Picture 4 Android UI-Tree Structure
To bind the screen to a tree for rendering, your activity calls its setcontentview () method and passes a parameter to the Root Node object. Once the Android system obtains the parameter of the root node, it can be invalidated directly through the node, ranging and drawing tree. When your activity is activated and focused, the system will notify you of the activity and request the root node to ranging and draw a tree, the root node will request its child nodes to draw their own, and the viewgroup node on each tree is responsible for drawing its direct child nodes.
As mentioned earlier, each view group has an effective space to measure it, layout its sub-objects, and call the draw () method of each sub-object to draw themselves. Sub-objects may request to obtain their size and location in the parent object, but the parent object has the final decision on the size and location of each sub-object.
Layoutparams: How to specify the position and size of a child object
Each viewgroup class uses a nested class inherited from viewgroup. layoutparams. This subclass contains a series of attribute types that define the position and size of a child object and adapt to the view group class.
Example of layoutparams:
Note that each layoutparams subclass has its own assignment syntax. Each child element must define the layoutparams that apply to its parent object, although the parent object may define different layoutparams for the child element.
All viewgroups contain width and height. Many also include boundary definitions (margin and border ). You can describe width and height very accurately, even though you don't want to do this too often. In more cases, you want your view to adjust the content size or container size.
Comparison between Android interface elements and swing interface elements
Android interface elements
Swing interface elements
Activities
Frame
Views
Components
Textviews
Labels
Edittexts
Textfields
Buttons
Buttons

Listener settings for Android and swing are almost the same:

3.2.2 General Layout objectThe following is the most common view groups in your application. This section describes some basic information about each type. For more details, see the reference pages of the previous links in each chapter.
Framelayout
FramelayoutIs the simplest layout object. It is customized as a blank standby area on your screen, and then you can fill in a single object-for example, an image you want to publish. All child elements are fixed in the upper left corner of the screen. You cannot specify a position for a child element in framelayout. The next child element directly overwrites the previous child element and blocks them in part or whole (unless the last child element is transparent ).
Linearlayout
LinearlayoutArrange all child elements based on the vertical or horizontal attribute values you set for it. All child elements are stacked behind other elements, so each row in a vertical list only has one element, no matter how wide they are, A horizontal list only has one row height (the height is the height of the highest child element plus the border height ). Linearlayout maintains the interval and alignment between child elements (right, middle, or left ).

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.