android结构图及运行流程分析

 idea里面的文件目录结构图分析:




1、asserts文件用于存放项目中用到的多媒体文件,但是与res的区别是res文件下的文件会在项目运行时被载入内存中,而asserts文件下的文件是在被用到的时候才会被载入内存中(这个很像hibernate中那个load跟get方法的区别有木有)。所以可以用于存放诸如视频文件、声音文件的大文件。

2、gen文件夹,该文件时自动生成的,其下存在一个R.java文件,这个文件可以理解为一个全局的资源文件的索引,我们来看一下这个文件的内容:

package com.example;

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 layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040000;
        public static final int hello=0x7f040001;
    }
}

 字段都被赋予了一个十六进制数,而这个文件中的所定义的常量的名字与res文件下的资源文件的名字是一致的,这个是不是很容易就会联想到数据库中的主键ID呢。当在Activity中需要调用资源文件中定义的值的时候就需要这个ID来获取了,例如:getResources().getColor(resourceId)可以调用color.xml中定义的资源

还有一个BuildConfig文件,这个文件可以理解成自定义常量集,有利于程序员们对程序的维护

3、libs文件夹,这个很明了,跟java项目中一样,是一个用于存放第三方jar包的文件

4、res文件夹,存放应用程序中的各类多媒体文件,按资源文件类型主要分为三个子目录drawable-*dpi、layout、values。

drawable文件夹用于存放图片文件,如png、jpg,上图中将drawable分成了四个子文件,主要是存放不同分辨率的图标,其中xdpi是超高分辨率,hdpi是高分辨率,mdpi是中等分辨率,ldpi是低分辨率;

layout文件夹用于存放页面布局的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>

 这表明是一个线性布局,布局里放了一个文本组件。文本组件中的@符号表示的是引用;

values文件夹是定义格式参数的xml文件,其中包括字符串描述文件strings.xml、颜色描述文件color.xml、数组描述文件array.xml、样式描述文件style.xml等。

5、src文件夹就是用于存放各种java源文件的

6、AndroidManifest.xml是 应用程序描述文件,类似于java项目中的web.xml,如下:

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

7、ant.properties文件用于在使用ant构建项目的时候覆盖某些被定义默认的值,例如

  'source.dir'本地的java源文件夹目录
  'out.dir' 本地编译项目输出的文件夹目录

8、loacal.properties文件是Android Tools自动生成的,主要包含一些本地特殊配置信息,如

sdk.dir=D:\\Program Files (x86)\\android\\sdk\\sdk

9、build.xml文件项目中的属性文件的配置文件

10、project.properties文件也是 Android Tools自动生成的

 

综合整理分析如图:

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章