`
zhangym124
  • 浏览: 342628 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Android开发之目录结构

阅读更多

Activity生命周期

  • 1、与一般的JAVA项目一样,src文件夹是项目的所有包及源文件(.java)。

  • 2、gen文件夹中包含了一个R.java,这个文件夹及类是在建立项目时自动生成的,这个文件是只读模式,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 com.example.practice;

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 menu_settings=0x7f070002;
        public static final int ok=0x7f070001;
        public static final int show=0x7f070000;
    }
    public static final class layout {
        public static final int activity_main=0x7f030000;
    }
    public static final class menu {
        public static final int activity_main=0x7f060000;
    }
    public static final class string {
        public static final int app_name=0x7f040000;
        public static final int hello=0x7f040003;
        public static final int hello_world=0x7f040001;
        public static final int menu_settings=0x7f040002;
    }
    public static final class style {

        public static final int AppBaseTheme=0x7f050000;

        public static final int AppTheme=0x7f050001;
    }
}

可以看到文件中定义了很多常量,这些常量的名字都与res文件夹中的文件夹名相同,这也说明了R.java是项目中资源索引。利用这个文件我们可以很快地找到要使用的资源。由于这个文件不能手动编辑,所以当在项目中加入了新的资源时,只需要刷新一下该项目,R.java文件便自动生成了所有资源的索引。

  • 3、Android 4.2是项目中要用到的包,这个文件夹在项目建立时自动生成。

  • 4、Android 系统为每个新设计的程序提供了/assets目录,这个目录保存的文件可以打包在程序里。/res 和/assets的不同点是,android不为/assets下的文件生成ID。如果使用/assets下的文件,需要指定文件的路径和文件名。

  • 5、接下来的res文件夹中包含了项目的所有资源,比如高低中分辨率程序图标文件(drawable-hdpi、drawable-ldpi、drawable-mdpi)、布局文件(layout)、常量(values)等。

1) 我们先来看看布局文件activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="18dp"
        android:text="@string/hello" />

</RelativeLayout>

  :线性版面配置,在这个标签中,所有的元素都是按由上到下的顺序排列的。

<RelativeLayout>: 相对布局配置。

  android:orientation:表示这个介质的版面配置方式,其中“vertical”代表从上到下垂直布局,而“horizontal”代表从左到右水平布局。

  android:layout_width:定义当前视图在屏幕上所占的宽度,fill_paent即填充整个屏幕。

  android:layout_height:定义当前视图在屏幕上所占的高度,fill_parent即填充整个屏幕。

  :文本标签,用来显示文字,高度设置“wrap_content”表示本文本标签可根据文本来改变高度。

  android:text:设置TextView要显示的内容,“@string/hello”表示引用String.xml文件中的hello所代表的字符串

2) 下面来看常量的定义(strings.xml文件):

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">practice</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="hello">hello</string>

</resources>
  • 6、接下来的AndroidManifest.xml文件,它是每个Android项目所必须的,是整个应用的全局描述文件。文件说明了应用的名称、所使用的图标、以及包含了该项目中所有使用的Activity、Service、Receiver等组件,该文件中代码如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.practice"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.practice.MainActivity"
            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>

  .:根节点,描述了package中所有的内容

  xmlns:android:包含命名空间的说明,该命名空间使得Android中各种标准属性能在文件中使用。

  Package:声明应用程序包。

  android:versionCode:该应用程序版本代号

  android:versionName:该应用程序版本名称

  uses-sdk:该应用程序所使用的SDK版本

  :包含package中application级别组件声明的根节点。此元素也可包含application的一些全局和默认的属性,如标签、icon、主题、必要的权限等。一个manifest中至多包含一个此元素

  android:icon:应用程序图标

  android:label:应用程序名

  Activity:Activity是用户打开的一个应用程序的初始页面,大部分被使用到的其他页面也由不同的Activity所实现。每个Activity必须有一个标记对应,无论它给外部使用或是只用于自己的package中。为了支持运行时查找Activity,可包含一个或多个元素来描述Activity所支持的操作。

  android:name:应用程序默认启动的Activity。

  intent-filter:声明了指定的一组组件支持的Intent值,从而形式了IntentFilter。除了能在此元素下指定不同类型的值,属性也能放在这里来描述一个操作所需的唯一标签、icon和其他信息。

  action:组件支持的Intent action

  category:组件支持的Intent Category。这里指定了应用程序默认启动的Activity。

  • 7、project.properties文件:

  记录项目中所需要的环境信息,比如Android的版本等,代码中的注释已经把project.properties解释得很清楚了:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
  • 8、proguard-project.txt文件

这个文件是混淆代码的脚本配置文件.

分享到:
评论

相关推荐

    最全的Android源码目录结构详解

    在深入解析Android源码目录结构之前,我们先了解下Android系统作为全球最大的移动操作系统之一,其内部结构复杂且庞大,涉及到硬件抽象层(HAL)、应用框架、核心库等多个层次。Android的源代码是开放的,这为开发者...

    unity android 目录结构1

    在Unity引擎中开发游戏或应用并将其部署到Android平台时,理解正确的目录结构至关重要,因为这直接影响到构建过程和最终APK的性能。本篇将详细介绍Unity导出Android项目的目录结构及其重要性。 首先,Unity在导出...

    Android SDK 中文开发文档&Android操作系统详细目录结构

    在Android开发领域,掌握SDK和操作系统目录结构是至关重要的。Android SDK是开发Android应用程序的基础工具集,它提供了构建、测试和调试应用所需的所有组件。本文将深入探讨Android SDK的中文开发文档以及Android...

    android源码目录结构

    Android 源码目录结构是 Android 操作系统的核心组成部分,了解 Android 源码目录结构是学习和开发 Android 应用程序的基础。本文将详细介绍 Android 源码目录结构,涵盖了 Android 2.1 版本的所有目录和子目录。 ...

    android开发项目目录结构.doc

    在Android开发中,项目目录结构是非常关键的一部分,它组织了应用程序的所有组件和资源,使得开发过程更为有序。本文将深入探讨Android开发项目目录结构,特别是针对一个基础的HelloWorld项目。 1.1、src 文件夹 `...

    Android开发之旅

    Android开发之旅:HelloWorld项目的目录结构 2 Android开发之旅:android架构 3 Android开发之旅:应用程序基础及组件 4 Android开发之旅:应用程序基础及组件(续) 5 Android开发之旅:活动与任务 6 Android...

    Android Studio下的APP目录结构详解

    Android Studio下的APP目录结构是Android应用开发中非常重要的一部分,对于初学者来说,了解目录结构可以帮助他们更好地理解项目的组织方式和文件的作用。本文将详细介绍Android Studio下的APP目录结构,帮助开发者...

    Android应用开发 目录结构

    用的是Java语言,其应用程序的目录结构是理解Android开发的基础。Android应用的结构分为多个层次,从上到下包括应用程序、应用程序框架、各种库和Android的运行时环境以及操作系统层。 1. **应用程序**:这部分是由...

    企业级Android开发

    04大话企业级Android开发_Android项目的目录结构、执行流程及其他基础分析 05大话企业级Android开发_MVC讲解及简单短信和拨号器实现 06大话企业级Android开发_日志输出、单元测试及调试 07大话企业级Android开发_UI...

    大话企业级Android开发

    04大话企业级Android开发_Android项目的目录结构、执行流程及其他基础分析 05大话企业级Android开发_MVC讲解及简单短信和拨号器实现 06大话企业级Android开发_日志输出、单元测试及调试 07大话企业级Android开发_UI...

    Android开发之旅:HelloWorld项目的目录结构

    在早期版本的Android开发中,可能需要特定版本的库文件来支持某些功能。 4. **assets 文件夹**:这个文件夹用于放置原始的非编译型资源,如文本文件、音频文件、JSON数据等。这些文件在运行时可以通过AssetManager...

    android开发揭秘PDF

    第1章 Android开发简介 1.1 Android基本概念 1.1.1 Android简介 1.1.2 Android的系统构架 1.1.3 Android应用程序框架 1.2 OMS介绍 1.2.1 OPhone介绍 1.2.2 Widget介绍 1.3 小结 第2章 Android开发环境搭建 2.1 ...

    android2.2源码目录结构详解

    ### Android 2.2 源代码目录结构详解 在深入理解 Android 源代码之前,熟悉其目录结构是至关重要的第一步。本文将基于 Android 2.2 的源代码,详细解析各个主要目录的作用及包含的主要文件类型,帮助开发者更好地...

    Android移动应用开发习题答案.pdf

    为了帮助开发者更好地学习和掌握 Android 移动应用开发技术,本文将提供一份详细的习题答案,涵盖 Android 开发环境搭建、模拟器创建、Android Studio 的组成结构与基本操作等多个方面。 一、Android 开发环境搭建...

    004_android 之项目的目录结构分析与资源引用

    在Android开发中,理解项目的目录结构以及如何正确引用资源是至关重要的基础。下面将详细解析Android项目的目录结构及其资源管理。 一、项目目录结构 1. `app`:这是你的应用模块,通常包含`src`、`build.gradle`...

    Android的目录结构

    Android应用程序的目录结构是开发者必须熟悉的基础知识之一。合理的目录组织不仅有助于保持项目的清晰性与可维护性,还能提高开发效率。本文将详细介绍Android项目的各个主要目录及其作用,帮助开发者更好地理解和...

    android开发入门教程

    第2章 工欲善其事 必先利其器——搭建Android开发环境 2.1 开发Android应用前的准备 2.1.1 Android开发系统要求 2.1.2 Android软件开发包 2.1.3 其他注意事项 2.2 Windows开发环境搭建 2.2.1 JDK、Eclipse、Android...

    企业级安卓开发_入门+进阶 大话企业级Android开发

    04大话企业级Android开发_Android项目的目录结构、执行流程及其他基础分析 05大话企业级Android开发_MVC讲解及简单短信和拨号器实现 06大话企业级Android开发_日志输出、单元测试及调试 07大话企业级Android开发_UI...

Global site tag (gtag.js) - Google Analytics