Open Eclipse, select File-new–android application Project
Application name is our app name and the name we see in the list of mobile apps.
Project name is the project title, the name we see in the project list in Eclipse, and the folder name we can see in workspace.
Package name is the package name, the Android system is also a very special name, he is not only the name of the package, or the name of the project in the Android system, the project name in the Android system needs to be unique, so we have to define the package name of the project must be careful not to duplicate names
Next we give the project a name, here I give it a name, called Firstandroid
Eclipse will help you to generate a default package name, please remember to modify the package name, general package name with the domain name inversion, if there is no domain name, you can use COM + 's own name of the abbreviation + category (Android or Java) + project name to form a unique project package name
Next, until finish, the first Android project was created. We can see the structure of the project
Where layout files are stored in layouts, we can see that by default we create a layout file called Activity_main.xml, open the file in eclipse, and we can see if the interface shown
There are 2 tabs at the bottom, the first tab is a graphical interface where we can drag the controls in, the second tab is a code area where we can edit the properties of the control.
Next we drag a button into the interface.
Then switch to Code view
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent" >5 6 <TextView7 Android:id= "@+id/tv_info"8 Android:layout_width= "Wrap_content"9 Android:layout_height= "Wrap_content"Ten Android:text= "@string/hello_world" /> One A <Button - Android:id= "@+id/btn_change" - Android:layout_width= "Wrap_content" the Android:layout_height= "Wrap_content" - Android:layout_alignleft= "@+id/tv_info" - Android:layout_below= "@+id/tv_info" - Android:layout_margintop= "30DP" + Android:text= "button" /> - + </Relativelayout>
The root node of the XML document above is Relativelayout, which represents a relative layout in which 2 controls are included:
- TextView Represents a text box
- A button represents a buttons control
The various interface layout elements are described in detail in subsequent chapters. The various UIs are also described in detail in subsequent courses, where we only introduce a few common properties.
Android:id: This property defines the unique identity of the control, which can be findviewbyid to get the specified interface component in Java code.
Android:layout_width: This property specifies the width of the control. We can use a fixed length value, or you can use Match_parent (which means the width of the control is the same as the width of the parent control), Wrap_content (indicating that the width of the control depends on the contents of the control)
Android:layout_height: This property defines the height of the control and the value that can be used refer to android:layout_width.
The SRC directory for Android projects is where Android source code is stored.
There is a mainactivity class file in SRC, the code is as follows
1 Packagecom.zy.android.firstandroid;2 3 ImportAndroid.os.Bundle;4 Importandroid.app.Activity;5 ImportAndroid.view.Menu;6 /**7 * 8 * @authorZhangyi9 * @bloghttp://www.cnblogs.com/blog-IT/Ten * One */ A Public classMainactivityextendsActivity { - - @Override the protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - //Load Layout file Activity_main.xml - Setcontentview (r.layout.activity_main); + } - + A @Override at Public BooleanOncreateoptionsmenu (Menu menu) { - //inflate the menu; This adds items to the action bar if it is present. - getmenuinflater (). Inflate (R.menu.main, menu); - return true; - } - in}
This Java class only does one thing-----load the layout.
So far, this firstandroid application has been developed and completed.
Then you can run the project.
Running an Android application via the Eclipse ADT plugin is simple, as long as the following 2 steps are required:
- Run the specified AVD device, and if you are ready to use the real machine as the running, debugging environment, you need to connect the phone with a USB cable and turn on debug mode.
- Select the Android item you want to run, right-click the Run as–android Application menu in the pop-up menu.
And then we can see our program on the simulator.
The first Android project has been run successfully and we will analyze the Android application structure
Learn android-with me. Develop your first Android app with Eclipse