Personal Android learning notes-the first Android Application

Source: Internet
Author: User

Today is the second day of studying Android. Yesterday we mainly learned how to configure the android development environment and the first Android program, helloworld. But it is not clearly explained. Now let's take a look at the steps required to develop Android applications using Eclipse:

1. Create an android Project

2. Define the UI of the vehicle worker in the XML layout File

3. Write Business implementation in Java code

The following describes how to develop a helloworld application:

1. Create an android project through ecclipse. You can select the project storage location, enter the project name, package name, and modify the activity class name, and modify the supported minimum Android version number.

2. You can see the created helloworld project structure:

3. There is a main. xml file under the layout directory of the android project, which is used to define the Android Application User Interface. Open this file

Switch to the source code writing interface and you can see

Now let's introduce a lot of the above Code:

The following element of XML is: linearlayout, which represents a linear layout, which contains two UI controls.

Xmlns: Android = "http://schemas.android.com/apk/res/android" is the namespace of XML

Android: layout_width = "fill_parent": Set the linerlayout width to the screen width.

Android: layout_height = "fill_parent": sets the height of linerlayout to the screen height.

Android: Orientation = "vertical": sets the direction of the linear layout to vertical.

Textview: a text box

Android: layout_width = "fill_parent": It should be noted that the fill_parent here is not the screen width, but the width of linearlayout, but now there is no difference because the width of linearlayout is the same as that of the screen.
Android: layout_height = "wrap_content": select a height based on the Content size.

Android: text = "@ string/Hello": @ refers to the automatically generated R file. String/Hello calls the content referenced by the "hello" character in the string in the r file.

However, we have noticed that the R file is automatically generated and the content in it cannot be changed at will; otherwise, problems may occur.

The place where the r file is automatically generated is our res resource folder. Because our content is not added, the content only comes from the string. XML in the values folder under the res folder.

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello World, HelloWorldActivity!</string>    <string name="app_name">HelloWorld</string></resources>

Hello world, helloworldactivity! One-to-one correspondence with R files

/* AUTO-GENERATED FILE.  DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found.  It * should not be modified by hand. */package cn.jimjarry.activity;public final class R {    public static final class attr {    }    public static final class drawable {        public static final int ic_launcher=0x7f020000;    }    public static final class layout {        public static final int main=0x7f030000;    }    public static final class string {        public static final int app_name=0x7f040001;        public static final int hello=0x7f040000;    }}

So far, our first Android Application has been developed. Now we need to run the android application through the ADT.

If the Android version we want to enable is not added to the AVD management, you must first add the corresponding version. Otherwise, it cannot be enabled.

If an android project has been added, right-click the android project and choose run as ----> choose Android Application. Then, the ADT plug-in automatically installs the project in the simulator.

After simulation, we can see our program

,

Have you seen it? Helloworld is printed correctly.

Now let's take a look at where the program icon is in the simulator.

OK. The first project demonstration is complete.

 

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.