Android (Interface Programming #7-Visual Programming)

Source: Internet
Author: User
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:

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.