WEB开发网
开发学院手机开发Android 开发 Android项目目录结构 阅读

Android项目目录结构

 2010-06-19 04:10:00 来源:WEB开发网   
核心提示:r.getString(R.string.hello));基本上可以定义出项目中所有使用的常量,例如颜色,Android项目目录结构(5),所以,可根据需对资源常量进行定义,而android:text则设置了这个TextView要显示的文字内容,这里引用了@string中的hello字符串,下面是定义了颜色的常量col
r.getString(R.string.hello));

基本上可以定义出项目中所有使用的常量,例如颜色。所以,可根据需对资源常量进行定义。下面是定义了颜色的常量colors.xml,如代码清单3-6所示。

代码清单3-6 colors.xml

< ?xml version="1.0" encoding="utf-8"?> < resources> < color name="status_idle">#cccccc < color name="status_done">#637a47 < color name="status_sync">#cc9900 < color name="status_error">#ac4444 < /resources>

现在我们来分析HelloAndroid项目的布局文件(layout),首先我们打开res->layout->main.xml文件,如代码清单3-7所示。

代码清单3-7 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>

代码清单3-7中,有以下几个布局和参数。

< LinearLayout >:线性版面配置,在这个标签中,所有元件都是按由上到下的排队排成的。

android:orientation:表示这个介质的版面配置方式是从上到下垂直地排列其内部的视图。

android:orientation:表示这里是水平排列

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

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

wrap_content:随着文字栏位的不同而改变这个视图的宽度或高度。

layout_weight 用于给一个线性布局中的多个视图的重要度赋值。所有视图都有layout_weight 值,默认为零,即需要显示多大的视图就占据多大的屏幕空间。如果值大于零,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的 layout_weight 值和该值在当前屏幕布局的整体 layout_weight 值,以及在其他视图屏幕布局的layout_weight 值中所占的比例。

在这里,布局中设置了一个TextView,用来配置文本标签Widget,其中设置的属性android:layout_width为整个屏幕的宽度,android:layout_height可以根据文字来改变高度,而android:text则设置了这个TextView要显示的文字内容,这里引用了@string中的hello字符串,即String.xml文件中的hello所代表的字符串资源。hello字符串的内容"Hello

上一页  1 2 3 4 5 6  下一页

Tags:Android 项目 目录

编辑录入:coldstar [复制链接] [打 印]
赞助商链接