Layout XML File Usage:
Just like the cross-platform UI library, Android uses XML files to store the layout of interface elements. Currently, some popular interface components use this method.
In Android, the Res/layout Resource Directory contains one or more. xml files. This is the layout file of the interface. Let's open one. I open the Res/layout/Main. xml file in the current project directory.
<? 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 = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"
Android: Id = "@ + ID/mainview"
/>
</Linearlayout>
The simple layout of this file refers to the use of a linearlayout layout, which contains only one textview interface element, that is, a view. When the activity loads the view, it can be directly loaded in oncreate. This. setcontentview (R. layout. main); where R. layout. main is a prime value, which is compiled and generated by the android development environment and mapped to RES/layout/main. XML.
Therefore, setcontentview (R. layout. Main); is equivalent to configuring a layout according to the layout of Main. xml,
Consistent with the following code
Linearlayout layout = new linearlayout (this );
Textview TV = new textview (this );
TV. settext (R. String. Hello );
Layout. addview (TV );
This. setcontentview (layout );
Here, R. String. Hello is also a resource ing ID, which is the value corresponding to hello in RES/values/string. xml.
The above example is a simple example. I know how to load the layout and how to generate the layout file?
Visual Programming:
Create a project and perform the aggregation as in the Hello, world example,
Find Res/layout/main on the left. double-click XML to open it. The Layout View of the XML file is automatically opened on the right side of eclipse. There are some layout toolbar operations around the view, and some of
Control to this view, the XML file will be changed. In the rightmost outline view, there is a tree structure of the interface elements in the layout file.
You can always play this game. It is no different from Visual vs, Delphi, swing, and QT. Let's take a small example: