Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1399297
  • 博文数量: 188
  • 博客积分: 1784
  • 博客等级: 上尉
  • 技术积分: 2772
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-05 22:20
个人简介

发上等愿,结中等缘,享下等福;择高处立,就平处坐,向宽处行。

文章分类

全部博文(188)

文章存档

2020年(12)

2019年(11)

2018年(4)

2017年(3)

2016年(11)

2015年(22)

2014年(19)

2013年(25)

2012年(32)

2011年(49)

分类: 嵌入式

2012-03-02 08:40:16

打开Hello Android 工程

Main.xml

  1. <LinearLayout></LinearLayout> 整体布局表示线性布局
  2. xmlns:android="" 名字空间
  3. android:orientation="vertical" 控件布局垂直往下布局
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent" 上层控件填充满
  6. <TextView
  7. android:layout_width="fill_parent" 横向填充满
  8. android:layout_height="wrap_content" 纵向按实际高度填充
  9. android:text="@string/hello" 要引用到的hello字符串
  10. /> 图形空间派生于View
  11. <Button
  12. android:id="@+id/widget40_button_OK" button控件ID
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content" 按实际宽度高度显示填充
  15. android:text="OK"
  16. ></Button>

AndroidManifest.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android=""
  3. package="com.example.android.helloactivity" >
  4. <application android:label="He llo, Activity!">
  5. <activity android:name="He lloActivity">
  6. <intent-filter>
  7. <action android:name="android.intent.action.MAIN"/>
  8. <category android:name="android.intent.category.LAUNCHER"/>
  9. </intent-filter>
  10. </activity>
  11. </application>
  12. </manifest>

其中package 用于说明这个包的名称,android:labeapplication 中的内容是表示这个应用程序
在界面上显示的标题,activity 中的android:name 表示这个Android 的活动的名称。

文件src/com/example/android/helloactivity/HelloActivity.java 是程序主要文件,由JAVA 语言
写成

 

  1. package com.example.android.helloactivity;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. public class HelloActivity extends Activity {
  5. public HelloActivity() {
  6. }@
  7. Override
  8. public void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.hello_activity);
  11. }
  12. }

com.example.android.helloactivity 表示的是这个包的名称, 在文件的头部引入了两个包
android.app.Activity 是一个Android 活动( Activity)包,每一个Android 活动都需要继承
Activity 类。
包android.os.Bundle 用于映射字符串的值。
onCreate()是一个重载的函数,在这个函数中实现应用程序创建的所执行的过程。其中
setContentView()设置当前的视图(View)。
设置的方法是使用一个文件,这个文件因此决定了视图中包含的内容。这里使用的是
R.layout.hello_activity,表示从res/layout/目录中使用hello_activity.xml 文件。
res/layout/hello_activity.xml 文件的内容如下所示:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <EditText xmlns:android=""
  3. android:id="@+id/text"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:textSize="18sp"
  7. android:autoText="true"
  8. android:capitalize="sentences"
  9. android:text="@string/hello_activity_text_text" />

其中定义了一个可编辑的文本( EditText),下面的各项其实是它的各种属性, android:text 表示这个文本的
内容,string/hello_activity_text_text 表示找到相应的文件, 也就是res/value/string.xml 文件中的
hello_activity_text_text 文本。
res/value/string.xml 的内容如下所示:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <string name="hello_activity_text_text" >He llo, World!>
  4. </resources>

hello_activity_text_text 文本被res/layout/hello_activity.xml 文件引用,正是应用程序运行时在
屏幕显示的文本。

重要包的描述:

android.app :提供高层的程序模型、提供基本的运行环境
android.content :包含各种的对设备上的数据进行访问和发布的类
android.database :通过内容提供者浏览和操作数据库
android.graphics :底层的图形库,包含画布,颜色过滤,点,矩形,可以将他们直接绘制到屏幕上.
android.location :定位和相关服务的类
android.media :提供一些类管理多种音频、视频的媒体接口
android.net :提供帮助网络访问的类,超过通常的java.net.* 接口
android.os :提供了系统服务、消息传输、IPC 机制
android.opengl :提供OpenGL 的工具
android.provider :提供类访问Android 的内容提供者
android.telephony :提供与拨打电话相关的API 交互
android.view :提供基础的用户界面接口框架
android.util :涉及工具性的方法,例如时间日期的操作
android.webkit :默认浏览器操作接口
android.widget :包含各种UI 元素(大部分是可见的)在应用程序的屏幕中使用

 

 

阅读(1342) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~