One: directory structure of Android project
Android Project Structure Overview. In fact, the directory structure of Android projects and Java almost, not much change, such as:
650) this.width=650; "Src=" http://dl.iteye.com/upload/attachment/348966/4a17123a-21bf-335f-8d0a-3e81b69531b1.png "Style=" border:0px; "/>
you can see the SRC folder is the source file, Android2.2 is the reference class library, these and Java are the same, then what is the following gen? The inside of the class is ADT automatically generated, generally only a R.java file, is not modified, then how he generated it, see the following res folder? R.java is generated according to the resource folder Res, R.java is the res in the resource file index, with a constant to mark a resource file in res, so that we reference in the code.
Now let's look at the Res folder, there are several categories below, where drawable is a picture, there are drawable-hdpi,drawable-ldpi,drawable-mdpi, corresponding to high-density images, low-density images, and medium-density pictures, If you want to use a picture, you do according to the density of the different three of the same picture into the three folders, then your application run on different resolutions of the machine, it will automatically select the appropriate image according to the resolution of the machine, how smart it! Is the relationship table of density and cell phone size.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/81/wKiom1Y6zN-AhAJWAAEUvkom_mw798.jpg "title=" 2. PNG "alt=" wkiom1y6zn-ahajwaaeuvkom_mw798.jpg "/>
-
Layout is the layout file., android supports the generation of views through xml , so that the view is separate from the logic-controlled code for easy administration.
values is our usual string, color values, arrays and so on .
The next AndroidManifest.xml is important, each Android project has one, this is the Android configuration file, where we can configure the app's properties , defining  ACTIVITY&NBSP, declaring the permissions used, and so on, is not specifically described here, and later chapters will talk about .default.properties is also a configuration file.
II: Specific explanation of the Android project file
First look at this HelloWorld class.
public class HelloWorld extends Activity {
/** called when the activity is first created. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}
}
He has inheritedActivity, in front of it, aActivityCan be imagined as a mobile phone screen to display the content of a screen, so all the screen to display content to inheritActivityCan be achieved, then cover theonCreate ()method on theActivityTo initializeSetcontentview (r.layout. main );Set up the useMain.xmlThis layout file is used as the currentActivityThe content of the show. Main.xmlis put inResUnderLayoutThe following fileXMLLayout file,We can directly useR.layout.mainMake a direct reference to him and that's alsoAndroidHighlight of the place, save us in order to cite aXMLFile re-useFileClass to read, all we have to do is put thisXMLThe index of the file toAndroid, he will automatically help us find it and use.
2. main.xml Layout file
<?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:text= "@string/hello"
/>
</LinearLayout>
The content of the layout file is not many, the beginning is a definition of a linearlayout component, and then in this linearlayout put a textview to display the text. Now take a look at a few parameters:
. LinearLayout a linear layout panel, only vertical and horizontal layout, android:orientation= "vertical" means that the child elements inside can only be arranged vertically, while using android:orientation= "horizontal "Horizontally arranges the child elements inside the logo.
. Android:text is this is TextView to display the text, can be a string, it can be a reference to a string, here is a reference, referring to the Strings.xml defined by the name Hello string
3. Strings.xml Introduction.
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "Hello" >hello World, helloworld!</string>
<string name= "App_name" >HelloWorld</string>
</resources>
Here we see that, as long as the definition of a k-v key value pairs, for other places to use. For example, the reference to Hello in main above. This has great significance for the unified management and internationalization of characters.
4. Introduction of Androidmanifest.xml
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.flysnow"
Android:versioncode= "1"
Android:versionname= "1.0" >
<application android:icon= "@drawable/icon" android:label= "@string/app_name" >
<activity android:name= ". HelloWorld "
Android:label= "@string/app_name" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<USES-SDK android:minsdkversion= "8"/>
</manifest>
This is an important configuration file for the project, such as Activity, permissions, Intent, etc. are configured here
Package: A bundle that defines the app.
Android:versiocode defines the version number of the app
Android:versionname defines the version name of the app
The application tag defines an application where a project has a maximum of one application tag.
android:icon= "@drawable/icon" defines icon images in the app's icons reference resource file
Android:label= "@string/app_name" defines the name of the app
The activity tag defines an activity, and each activity must be defined here, otherwise it cannot be run.
Android:name defines the class name of the Activity, here. HelloWorld is based on the package definition above, which is the package (Com.flysnow) plus this android:name (. HelloWorld) to be able to locate the Activity (Com.flysnow.HelloWorld), otherwise it is not found.
Android:label defines the title of the Activity
Intent-filter defines a intent filter that is used to mark the activity so that the Android system can find the activity, defined as a hidden intent, mainly using two sub-tags action and category to zone Divide each Intent.
The final <uses-sdk android:minsdkversion= "8"/> is the level of the lowest SDK that defines the app!
This article is from the "No Water Fish" blog, please be sure to keep this source http://javaqun.blog.51cto.com/10687700/1709928
Android Series tutorial for Android project directory structure