您的位置:首页 > 移动开发 > Android开发

关于Android新手应该先了解的知识

2015-01-25 16:06 239 查看

Android初学者需知(笔者是新手)

关于Android环境的搭建、安装和配置,笔者就不再多说了这些网上、书上众多都可找到。(现在有了一个Android Studio软件,是一款专门为Android应用开发的开发工具,不过现在是初学阶段笔者觉得不适合去使用,毕竟工具刚出来和初学阶段书籍上的工具差别较大,不可能边学知识边研究工具吧)

不管做什么工作,都必须先熟知自己有什么资源,需要用到什么以及所对应的资源放在哪里。所以这里笔者罗列以下几个需要了解的部分:

1.Src

src文件夹是源文件所在的文件夹,和java中的基本是一样的,我们把定义好的java类文件放在这个文件夹里。我们的代码编写都是在这里进行的,同时文件目录的结构以及包组织结构和java也是一样的,毕竟都是eclipse开发工具中开发的嘛。

2.Gen

Gen文件夹是一些自动生成的资源,这是和之前编写java应用的时候的最大的不同,里面有一个名为“R”的类(R.java),这是在我们声明配置一些组件的时候,保存的时候自动生成的。虽然我们可以编辑里面的文件,但是其实是没有用的,因为我们修改了之前的配置再次保存之后,之前手动修改的就不见了,所以一般不用去管他。但是我们也应该了解一下。R文件是(Resourse)资源的意思

package com.example.tablelayout;

public final class R {

public static final class attr {

}

public static final class dimen {

/** Default screen margins, per the Android Design guidelines.

Customize dimensions originally defined in res/values/dimens.xml (such as

screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.

*/

public static final int activity_horizontal_margin=0x7f040000;

public static final int activity_vertical_margin=0x7f040001;

}

public static final class drawable {

public static final int ic_launcher=0x7f020000;

}

public static final class id {

public static final int EditText=0x7f080003;

public static final int TableLayout=0x7f080000;

public static final int TableRow=0x7f080001;

public static final int action_settings=0x7f080006;

public static final int cancle=0x7f080005;

public static final int ok=0x7f080004;

public static final int textView01=0x7f080002;

}

public static final class layout {

public static final int activity_table_layout=0x7f030000;

public static final int table=0x7f030001;

}

public static final class menu {

public static final int table_layout=0x7f070000;

}

public static final class string {

public static final int action_settings=0x7f050001;

public static final int app_name=0x7f050000;

public static final int hello_world=0x7f050002;

}

public static final class style {

/**

Base application theme, dependent on API level. This theme is replaced

by AppBaseTheme from res/values-vXX/styles.xml on newer devices.

Theme customizations available in newer API levels can go in

res/values-vXX/styles.xml, while customizations related to

backward-compatibility can go here.

Base application theme for API 11+. This theme completely replaces

AppBaseTheme from res/values/styles.xml on API 11+ devices.

API 11 theme customizations can go here.

Base application theme for API 14+. This theme completely replaces

AppBaseTheme from BOTH res/values/styles.xml and

res/values-v11/styles.xml on API 14+ devices.

API 14 theme customizations can go here.

*/

public static final int AppBaseTheme=0x7f060000;

/** Application theme.

All customizations that are NOT specific to a particular API-level can go here.

*/

public static final int AppTheme=0x7f060001;

}

}

打开一个R文件,其实可以很直观的看到,里面只有一些变量而且是都是final修饰的。之前说了R文件是资源的意思但他本身并不是资源,其实他是可以说是相关的程序和资源之间联系的一个纽带,他是一种索引,既然是索引那么他的每个索引必须是不可重复的,这样也就可以理解为什么用final来修饰了,确保每个变量的唯一性。

3.Android X.X

这是一个平台类库,是在建立application的时候就已经选择好了的,同时建议尽量不要再导入第三方类库,因为我们选择好生产的平台类库中的内容是和真正的Android操作系统中的类库是一样的,否则会存在平台兼容性的问题,而且它能提供绝大多数应用功能的要求。不过我们可以通过修改工程文件配置来切换平台版本。通过这个特性,我们可以检查我们应用程序针对不同平台的兼容性和可移植性。

4.Assets

这个文件是用来存放用户管理的各种文件和文件夹(一般用不到,毕竟android已经提供了比较完善的应用数据和资源管理方式)。

5.Res

res资源文件夹中我们可以定义和保存各种资源文件,比如layout界面布局文件,values/string字符串,drawable界面元素,主题,图片,音频视频等等。

6.Android Manifest.xml

这是当前android应用工程的配置文件,相当于java EE中的web.xml。这个文件可以定义当前android应用程序的相关配置,包括应用程序名称,版本,图标等内容,以及应用权限,所包含的视图和行为等等。

关于Android Application Project中的结构,以及其所代表的含义简单来讲有这么一些,其中的细节笔者还没研究透,就先写这些。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: