Android Android-use Eclipse to develop the first android Application, android-android
Open Eclipse and select File-New-Android Application Project
Application Name is our Application Name, which is also the Name we see in the mobile app list.
Project Name is the Project Name. It is the Name we can see in the eclipse Project list and the folder Name we can see in workspace.
Package Name is the Package Name. The Package Name in the Android system is also a special thing. It is not only the Package Name, but also the project Name in the Android system, the project name must be unique in the Android system. Therefore, when defining the package name for the project, you must note that the project name cannot be duplicated.
Next we will give a name to the project. Here I will give it a name for the moment, called FirstAndroid
Eclipse will help you generate a default package name. Please remember to change the package name. Generally, the package name is put upside down by domain name. If there is no domain name, you can use com + your own name abbreviation + classification (android or java) + project name to form a unique project package name
Next, click Next until finish. The first Android project is created. The project structure we can see
Here, layout stores our layout file. We can see that a layout file named activity_main.xml is created by default and opened in eclipse, we can see the interface shown in
There are two tabs at the bottom. The first tab is a graphical interface. We can drag the control here, and the second tab is a code area. We can edit the control attributes here.
Next, drag a button to the interface.
Switch to the Code view
1 <RelativeLayout xmlns: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 <TextView 7 android:id="@+id/tv_info" 8 android:layout_width="wrap_content" 9 android:layout_height="wrap_content"10 android:text="@string/hello_world" />11 12 <Button13 android:id="@+id/btn_change"14 android:layout_width="wrap_content"15 android:layout_height="wrap_content"16 android:layout_alignLeft="@+id/tv_info"17 android:layout_below="@+id/tv_info"18 android:layout_marginTop="30dp"19 android:text="Button" />20 21 </RelativeLayout>
The root node of the above XML document is RelativeLayout, which represents a relative layout. In this layout, there are two controls:
- TextView: Text Box
- Button indicates the Button control.
We will give a detailed introduction to various interface layout elements in subsequent chapters. Various UIS will also be described in detail in subsequent courses. Here we will only introduce a few general attributes.
Android: id: This property defines the unique identifier of the control. In Java code, you can use findViewById to obtain the specified interface component.
Android: layout_width: This attribute specifies the width of the control. We can use a fixed length value or match_parent (indicating that the width of the control is the same as that of the parent control) and wrap_content (indicating that the width of the control depends on the content of the control)
Android: layout_height: This attribute defines the height of the control. For available values, see android: layout_width.
The src directory of the Android project is the place where the Android source code is stored.
Src contains a MainActivity class file. The Code is as follows:
1 package com. zy. android. firstandroid; 2 3 import android. OS. bundle; 4 import android. app. activity; 5 import android. view. menu; 6/** 7*8 * @ author zhangyi 9 * @ blog http://www.cnblogs.com/blog-IT/10 * 11 */12 public class MainActivity extends Activity {13 14 @ Override15 protected void onCreate (Bundle savedInstanceState) {16 super. onCreate (savedInstanceState); 17 // load the layout file activity_main.xml 18 setContentView (R. layout. activity_main); 19} 20 21 22 @ Override23 public boolean onCreateOptionsMenu (Menu menu) {24 // Inflate the menu; this adds items to the action bar if it is present.25 getMenuInflater (). inflate (R. menu. main, menu); 26 return true; 27} 28 29}
This Java class only does one thing-load the layout.
So far, the FirstAndroid application has been developed.
Then you can run the project.
Using the ADT plug-in of eclipse to run Android applications is very simple, as long as the following two steps:
Next we can see our program on the simulator.
The first android project has been successfully run. Next we will analyze the android Application structure.
How to Set up an android development environment in eclipse?
In eclipse, configure the android development environment. In Eclipse, develop the android Application software. In Eclipse, configure the software development configuration for android: 17: 07Eclipse: develop the software development configuration for android Application Software on Eclipse; it turns out that when Google's Android plug-in download URL is not suspended, everything is easy to install, and now it is harmonious (I don't know why it is harmonious), I can only find it from the Internet a little bit; One: 1: Download jdk, install 2: Download eclipse (I installed 3.5). Attachment: it is best not to use myeclipse because it is not open source. You 'd better use open source, I did not elaborate on the previous two steps in line with android, because many 3: Google (Baidu) Search for android sdk (I searched for android sdk2.2); 4: Download, the size is about 70 MB (my next one). Note that many users leave a message saying it is false after the download. In fact, the download is not an sdk, but an sdk Download Manager, prepare for subsequent downloads (the storage path and file name are set to English, no It is important to include Chinese characters !) 5: After the download, You need to download an android adt plug-in (Baidu search), which is used to provide eclipse with an android interface (which I understand); Two: 1: after downloading the preceding configurations, start eclipse (assuming that you have installed eclipse and jdk ), click help-> software updates -- à Available Software-à Add Sites (on the far right of the window)-à local to find the adt folder (Archive) is used to select the compressed file, à OK will have some more things with android, select all, and click install; it may take some time, patience .... Restart eclipse2 after successful restart: some more things will be found after restart: Then window-à preference adds Android, and click "apply" and click "ok3: click window-à android sdk and avdmanage and click available packages to select the version you want to load. If the network speed permits, download all the versions. I will download 2.2 first and then download the version; click install selected to download 4: After the download, click window-à android sdk and avdmanage-à verify ure device (full screen display to prevent invisible), and click create AVD on the far right of the new device, I have created hhh and s (names can be selected at will), selected one, and then clicked start-> lunmethane on the rightmost side. The simulated mobile phone is displayed. 5: Finally One-Step Project Creation, android project creation, and running will be automatically displayed on the simulated mobile phone!
Android Application Development Using eclipse
You are engaged in Art. It is correct to design it to 480*800, which basically satisfies the width and height of each device. The reason why the image size is different is that the density of each device is different, the relationship between the dp and px in the medium density is, that is, the size of the converted image in the pixel program is, and that in the high density is. 5. The system will increase the image pixel by 1.5 times. At low density, it is. 75. If you look at the source code of the system, you will know that the processing method of the system is to put images of different sizes under different density. For example, put drawable_hdpi (high density) into a 64*64 image, drawable_mdpi (medium density) into a 48*48 image, drawable_ldpi (low density) put a 32*32 image (in proportion ).
If you think this is troublesome, put it under one density, and the system will judge that if you cannot find the image under that density, you will find it under another density and then convert it. Therefore, you can only store the 64*64 image at a high density (of course, it may be distorted. After all, it scales the image proportionally ).
The above is the processing method on the image, and there is another method that the programmer needs to do, that is, when the layout is set, the layout_weight of LinearLayout is used, because according, there is a proportion in the content, so set the same proportion in the layout, so that no matter what device, it will be displayed in this proportion, of course, this method will increase the workload of programmers. After all, each layout must adopt a linear layout.
I hope this will help you, but I don't know how to communicate with you... Also, when I had worked so hard that I had not sent it out, I encountered an error and beat it again .. Depressed !!!