用Eclipse打开Android应用程序的项目可以看到如下图所示的文件结构。

Android应用程序项目结构_第1张图片

src文件夹保存的是我们编写的java源文件,我们编写的源代码一般都放在这个文件夹内。比如HelloAndroid.java这个文件就是我们编写的代码文件。

package org.leo.android; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("hello,android"); tv.setBackgroundColor(Color.BLUE); setContentView(tv); } }

gen目录的R.java是自动生成的,每一个在res目录中的资源文件都会在R.java中生成一个与资源文件同名的变量,并且由系统自动赋给每一个变量唯一的一个ID,在程序中可以直接引用ID来获取元素。

R.java

/* 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 org.leo.android; public final class R { public static final class attr { } public static final class drawable { public static final int icon=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; } }

Android3.0目录中有android.jar文件,我们在项目中引用的所有android提供的类都来源于这个jar文件。

assert目录和res目录都可以放项目中要用到的资源文件和一些类文件。但是assert目录和res目录的区别是res目录中的所有资源文件都会自动在gen/R.java文件中自动生成相应的ID。而asser目录中的文件则不会在R.java中自动生成相应的ID。

res目录中的三个文件夹drawable-hdpi,drawable-mdpi,drawable-ldpi表示Android应用程序在高分辨率,中分辨率,低分辨率的屏幕上的不同显示版本。这样可以使得我们编写的Android的应用程序在不同分辨率和大小的屏幕上运行时仍然保持界面的美观。所以程序有三个不同的显示版本。layout里面放置的是布局文件main.xml。每一个Activity都对应着一个xml文件,xml文件控制着activity界面中各种控件的位置以及大小,宽度等一些属性。values/strings.xml文件保存的是一些键值对<string类型的变量,变量的值>。strings.xml中的变量也会在R.java生成相应的ID。R.java相当于为项目中的资源文件提供了一个统一的引用入口。这样做的好处是可以在项目中引用不同的strings.xml文件从而实现不同的语言版本,有利于软件的国际化。

main.xml

<?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:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>

strings.xml

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

AndroidManifest.xml是整个应用程序的配置文件。在这个文件中保存了引用程序的图标,标签,版本,以及启动应用程序时最先启动的Activity等信息。

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.leo.android" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="11" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloAndroid" 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> </manifest>

更多相关文章

  1. Android 自动识别TextView或者EditView里的url并在自己的应用程
  2. Android Studio添加so文件并打包到APK的lib文件夹中
  3. android studio打包 so文件
  4. android手把手教你开发launcher(三)——启动安装的应用程序
  5. Android应用程序永久获取root权限方法
  6. Android中Application、静态变量和Sharedpreferences的使用与区
  7. Android 完全退出应用程序实现代码

随机推荐

  1. Android(安卓)获取SIM卡内信息(TelephonyM
  2. 【android-tips】android程序执行adb she
  3. Android(安卓)如何获取摄像头所支持的所
  4. Android(安卓)获取通话记录
  5. android上传视频
  6. android执行Linux命令
  7. Android(安卓)4.0源码编译错误
  8. Android(安卓)监控网络状态
  9. Android(安卓)读写文件整理
  10. How to build Android(安卓)Windows SDK