Android directory structure (detailed)

Source: Internet
Author: User

Android directory structure (detailed)

The following is the directory hierarchy of the Helloandroid project in Eclipse:

You can see that there are nine files in the root directory of the project (clip), the following nine files (clips) to explain:

1.1SRC folders and Assets folders:

Each Android program contains a resource directory (SRC) and an Asset directory (assets), and the resources and assets don't sound much different, but when you store external content more resources (SRC), The difference is that the content stored under the resource (SRC) can be accessed through the application's R class, while the content stored in the asset (assets) remains in the original file format and, if required, must be read in a byte stream, using Assetmanager. It's very inconvenient to use. For ease of use, files and data are usually stored in the resource (SRC) directory

1.2res (Resource) directory: Resource Directory

can store some icons, interface files and text messages used in the application, for the Res directory:

1.2.1 drawable-*dpi folder: Place icons in different directories at the highest resolution, where draeable-hdpi is used to store high-resolution icons, drawable-mdpi for medium-resolution icons, DRAWABLE-LDPI to store low-resolution icons

1.2.2 Values folder: Information for storing text

(1) Strings.xml: Used to define strings and values

<?xml version="1.0"encoding="Utf-8"?>

<resources>

<string name="Hello">hello world, Hello 3g</string>

<string name="App_name">Android1.1</string>

<string name="Test"> Brother Miss You </string>

<string name="Startbutton"> button 1</string>

<string name="Start"> button 1</string>

</resources>

Each string tag lives a string, and the Name property specifies its reference value

(2) Why should these appearing text be placed in the Strings.xml file separately?

Answer: First, for internationalization, if you need to change the text in the file to another country's language, you can only need to replace a strings.xml file.

The second is to reduce the volume of the application, for example, we want to use in the application "elder brother Miss You" this sentence 1000 times, if we did not "think you" in the Strings.xml file, but rather directly in the application to write these words, then we will write 4,000 characters in the application. 4,000 words and 4 words occupy the memory but there is a big gap, and the cell phone memory is small, so should be able to save the province

(3) There are also arrays.xml,color.xml, such as the definition of arrays, colors, it is best to use a separate XML document

1.2.3 Layout file: Used to store interface information

The layout file in this example is an auto-generated "Main.xml"

<?xml version="1.0"encoding="Utf-8"?>

<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"

Android:layout_width="Fill_parent"

android:layout_height="Fill_parent"

android:orientation="vertical">

<textview

Android:layout_width="Fill_parent"

android:layout_height="Wrap_content"

android:text="@string/test"/>

</LinearLayout>

<LinearLayout> elements: Linear layout meaning that all child elements under this element will be based on his "orientation" property to determine whether the layout is by row or column or by display.

<TextView> element: is a display control whose "text" property specifies what is displayed on this element

1.3 Gen Directory: Only one automatically generated "R.java" file in the Gen directory

/*auto-generated FILE. Do not MODIFY.

*

* This class is automatically generated bythe

* aapt tool from the resource data itfound. It

* Should not being modified by hand.

*/

Package Cn.csdn.android.demo;

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 ID {

Public static final int button1=0x7f050000;

Public static final int radiobutton1=0x7f050001;

Public static final int togglebutton1=0x7f050002;

}

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;

Public static final int start=0x7f040004;

Public static final int startbutton=0x7f040003;

Public static final int test=0x7f040002;

}

}

R.java file: The default is attr,drawable,layout,string four static inner classes, each static inner class corresponding to a resource, such as layout static internal class corresponding to the interface file in Layout, The string static inner class corresponds to a string label inside a string. If you add an interface file in layout or add a string tag within a string, R.java automatically adds the added content to its corresponding inner class.

R.java In addition to the automatic identification of the index function of the resource, there is another function, that is, when a resource in the Res file is not used in the application, when the application is compiled, the system does not compile the corresponding resources into the APR package in the app.

1.4 Androidmanifest.xml Feature manifest file

Each application will have a androidmanifest in its root directory. This checklist provides basic information about the app for Android, which must be known before it is run, and if we use the system's own services, such as dial-up services, app installation Services, etc., you must declare the permissions in the Androidmanifest.xml file.

Features of the Androidmanifest.xml:

The Java application package that names the application, which uniquely identifies the application;

Describes the components of an application, naming the classes that implement each component and advertise its functionality, which makes the Android system aware of the components and under what conditions they can be started

Decide which component runs in which process

Declares the permissions that an application must have to access the protected API, and to interact with other processes

Declaring other prerequisite permissions for the application for interaction between components

List the libraries that application need to link

Use the Helloandroid project's function list as an example to explain:

<?xml version="1.0"encoding="Utf-8"?>

<manifest xmlns:android="Http://schemas.android.com/apk/res/android"

package="Cn.csdn.android.demo"

android:versioncode="1"

Android:versionname="1.0">

<USES-SDK android:minsdkversion="8"/>

<application

android:icon="@drawable/ic_launcher"

Android:label="@string/app_name">

<activity

Android:label="@string/app_name"

Android:name=". Helloactivity ">

<intent-filter >

<action android:name="Android.intent.action.MAIN" />

<category android:name="Android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

1.4.1 <manifest> Elements

<manifest xmlns:android="Http://schemas.android.com/apk/res/android"

package="Cn.csdn.android.demo"

android:versioncode="1"

Android:versionname="1.0">

The <manifest> element is the root element of Androidmanifest.xml, and "xmlns:android" refers to the file's namespace, and the "package" attribute is the one in which the Android app resides, "Android: Versioncode "Specifies the version number of the app, if the application is constantly upgraded, you need to modify this value," Android:versionname "is the name of the version, which can be changed according to your favorite

1.4.2 <application> Elements

<application

android:icon="@drawable/ic_launcher"

Android:label="@string/app_name">

<activity

Android:label="@string/app_name"

Android:name=". Helloactivity ">

<intent-filter >

<action android:name="Android.intent.action.MAIN"/>

<category android:name="Android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

The <application> element is a very important element, and the development component is defined here

The "icon" attribute of the <application> element is the icon used to set the app, where "@drawable/ic_launcher" means: icon in the drawable static inner class in the R.java file, as shown in

The "label" attribute of the <application> element is used to set the name of the app, where "@string/app_name" is the same as above, and is also under the string static inner class in the R.java file app_name

1.4.3 <activity> Elements

<activity

Android:label="@string/app_name"

Android:name=". Helloactivity " >

<intent-filter >

<action android:name="Android.intent.action.MAIN" />

<category android:name="Android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

The role of the <activity> element is to register an activity message, and when we create the "helloandroid" project, we specify the "Created activity" property as "Helloactivity", ADT then helped us create an activity automatically when the project was built, which was "Helloactivity.java";

The "name" attribute of the <activity> element specifies the class name of the activity, where ". Helloactivity "in the". " Refers to the current package specified in the "packages" attribute in the <manifest> element, so ". Helloactivity "is equivalent to"Cn.csdn.android.demo.HelloActivity.java", if the activity in the app's package can not write". ", but in order to avoid errors, or write this point

1.4.4<intent-filter> elements

<intent-filter >

<action android:name="Android.intent.action.MAIN" />

<category android:name="Android.intent.category.LAUNCHER" />

</intent-filter>

<intent-filter> if the direct translation is the "intent filter", the component through <intent-filter> tells them the function, that is, can respond to the intent type, set the action in intent, data, Categroy after the same property is set in the corresponding intentfilter can be filtered by the activity call

Minimum Android version required to run 1.5<project.properties> app

1.6<android 2.2> Storage of Android's own jar package

"References" http://www.oschina.net/question/234345_53839

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.