`
zhangym124
  • 浏览: 339281 次
  • 性别: 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开发项目目录结构.doc

    android开发项目目录结构

    Android应用开发 目录结构

    Android 应用开发目录结构,各文件夹的作用

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

    包括: Android SDK 中文开发文档(高清): 关于安卓开发的,相当不错的资料关于安卓开发的,看文档能学到很多东西 Android操作系统详细目录结构

    Android开发之旅 完整版pdf

    作者:吴秦 ...本文基于署名 2.5 中国大陆许可协议发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的署名吴秦(包含链接). • Android 开发之旅:环境...• Android开发之旅: Intents和Intent Filters(理论部分)

    Android开发之旅

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

    Android项目的目录结构和程序的执行流程

    Android项目的目录结构和程序的执行流程

    Android开发之旅——完整版

    挺不错的开发资料,上传赚分。 • Android 开发之旅:环境搭建及HelloWorld • Android 开发之旅:HelloWorld项目的目录结构 • Android 开发之旅:...• Android开发之旅: Intents和Intent Filters(理论部分)

    企业级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开发揭秘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 ...

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

    简单地建立一个HelloWorld项目,本篇将通过HelloWorld项目来介绍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...

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

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

    Android开发 vivox9plus手机设置结构目录

    Android开发 vivox9plus手机设置结构目录

    Android开发相关的学习资料

    Android资源_01-Android开发环境搭建_实验01-Android开发环境搭建.pdf、实验02-Android应用开发HelloWorld.pdf; 02-Android Studio项目结构分析与调试_实验03-Android Studio项目结构分析.pdf、实验04-Android ...

    Android开发与应用——张荣 原书配套例程代码

    第1章 Android简介 1.1 手机操作系统 1.2 Android起源 1.3 Android特征 1.4 Android体系结构 1.4.1 应用层 1.4.2 应用框架层 1.4.3 系统库层 1.4.4 内核层 1.5 小结 练习 第2章 Android开发环境 2.1 ...

    安卓Android开发电子书大全 2018 (1/4)

    Android嵌入式智能操作系统是基于Linux内核和驱动的,对于HTC、华为等公司开发Android操作系统时,需要专门将Android移植到 特定硬件平台下,同时将必要的驱动进行编写及开发。...Google.Android开发入门与实战.rar

    二、Android开发环境配置-Android开发与实践

    掌握Android开发环境的安装配置方法 了解Android SDK的目录结构和示例程序 了解各种Android开发工具的用途

Global site tag (gtag.js) - Google Analytics