单击以编辑母片 Content 标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 2

Similar documents
PowerPoint Presentation

Microsoft Word - 第3章.doc

Microsoft PowerPoint - 04 界面编程.ppt [兼容模式]

Android Fragment

人民邮电

预览图 : (2) 在 SelectCity.java 中增加控件, 用于绑定 select_city 文件的 ListView, TextView,EditTest 等控件 代码和注释如下 :

小应用 Magic8

PowerPoint 簡報

Dynamic Layout in Android

象 )? 3 车» 卒 帅 卒 帅 ( 帅 帅 1 帅 ) 3 ( ) L 4

内文-2.indd

Microsoft PowerPoint - 05.Android 介面元件-RelativeLayout、Button、TextVeiw、EditText

Microsoft PowerPoint - chapter05.ppt

單步除錯 (1/10) 打開 Android Studio, 點選 Start a new Android Studio project 建立專案 Application name 輸入 BMI 點下 Next 2 P a g e

任务实施 (1) 创建项目 图 3-1 欢迎界面 首先创建一个工程, 将其命名为 BoXueGu, 指定包名为 com.boxuegu (2) 导入界面图片将欢迎界面所需要的背景图片 launch_bg.png 导入到 drawable 文件夹中, 项目的 icon 图标 app_icon.png

「西醫基層總額支付委員會《第28次委員會議紀錄

Chapter 4

Android Android Android SDK iv

Android Service

Google Android 應用程式開發實戰

图 6-1 主界面 MainActivity 界面对应的布局文件 (activity_main.xml) 如下所示 : <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="

团 学 要 闻 我 校 召 开 共 青 团 五 届 九 次 全 委 ( 扩 大 ) 会 议 3 月 17 日, 我 校 共 青 团 五 届 九 次 全 委 ( 扩 大 ) 会 议 在 行 政 办 公 楼 五 楼 会 议 室 举 行, 校 团 委 委 员 各 院 ( 系 ) 团 委 书 记 校 学 生

Microsoft Word - 02.目錄.doc

0511-Android程式之GPS應用_專題週記4

<4D F736F F D205BCAE9B0FCCDF85DC8FDC9FAC8FDCAC0CAAEC0EFCCD2BBA82E646F6378>

Android + NFC

Lecture01_Android介绍

上海市教育委员会文件

第6讲

山东建筑大学学分制管理规定(试行)

電機工程系認可證照清單 /7/1

Microsoft Word - 第3章.doc

2 从列表选择在添加黑名单界面中, 点击 从联系人中添加 按钮时, 会跳转到联系人列表界面, 点击其中的任意一个联系人, 此时该联系人的电话号码和姓名会显示在添加黑名单界面的编辑框中, 点击下方的 添加 按钮, 此时会将该号码添加到黑名单中, 并在主界面中展示, 如图 3-2 所示 图 3-2 从联

Microsoft PowerPoint - 07.Android 介面元件-TableLayout、Toast、AlertDialog

Android + WebService

XXX说明书

建立Android新專案

Microsoft Word - ACL 作者序

90 深入 Android 应用开发 核心技术解析与最佳实践 -> android.view.viewgroup -> android.widget.linearlayout 对于 LinearLayout 而言 有几个重要的属性必须注意 android:layout_width 属性定义了控 件的

Photoshop CS6 艺术设计案例教程 ( 第二版 ) 1.1 Photoshop 的应用领域 Photoshop,,, Photoshop Photoshop 的用途 Photoshop CIS ( ) ( ) 案例展现 ~ 1

03 开发入门.key

目 錄 一 ANDROID 開發系統需求 作業系統 開發工具... 1 二 安裝 ANDROID 開發工具 安裝 JDK 使用 APT-GET 安裝 使用套件管理程式安裝... 9 三 ANDROID 程式撰寫... 1

中 文 摘 要 智 慧 型 手 機 由 於 有 強 大 的 功 能, 以 及 優 渥 的 便 利 性, 還 能 與 網 路 保 持 隨 時 的 鏈 結 與 同 步 更 新, 因 此 深 受 廣 大 消 費 者 喜 愛, 當 然, 手 機 遊 戲 也 成 為 現 代 人 不 可 或 缺 的 娛 樂 之


壹 前 言 解 開 2048 的 謎 一 研 究 動 機 最 近 我 們 都 很 熱 衷 於 2048 這 款 遊 戲, 遊 戲 方 法 非 常 簡 單, 但 是 想 要 達 成 2048 卻 很 難, 每 次 只 差 臨 門 一 腳 就 能 達 到 2048, 因 此 都 沒 有 成 功 過 於

通信网与SDH传输系统

Microsoft Word - 第3章.doc


概述

投影片 1

Microsoft Word - AEL CH05.doc

3. 反 映 : 4. 五 花 八 门 : 5. 慷 慨 : 6. 参 与 : 7. 慰 劳 : 8. 延 续 : 9. 珍 爱 : 10. 浪 漫 : 三. 找 出 下 列 每 组 词 中 的 近 义 词 或 同 义 词 : 节 日 节 气 节 令 时 节 习 俗 民 俗 仪 式 风 俗 文 献

第 一 部 分 就 业 基 本 情 况 前 言 河 北 师 范 大 学 是 河 北 省 人 民 政 府 与 教 育 部 共 建 的 省 属 重 点 大 学, 具 有 一 百 余 年 的 发 展 历 史 和 光 荣 的 办 学 传 统 校 友 中 有 老 一 代 革 命 家 邓 颖 超 刘 清 扬 郭

Android 应 用 开 发 实 践 教 程 进 行 控 制, 这 也 是 较 为 推 荐 的 一 种 方 式 动 态 方 式 是 指 通 过 Java 代 码 来 开 发 用 户 界 面, 动 态 地 控 制 界 面 中 的 组 件 XML 布 局 文 件 控 制 用 户 界 面 利 用 XML

PowerPoint Presentation

<D6D0B9FAD6A4C8AFCAD0B3A1C5FAC5D02E D20BCC7CAC2B1BE>

第 5 章 Android 控件进阶操作实战 ArrayAdapter 适配器 ListView 的数据渲染都需要借助适配器来完成, 首先看一下结合最简单的 ArrayAdapter 来实现 ListView 主布局文件 (activity_main.xml) 代码如下 : <?

马 克 思 主 义 学 院 经 济 与 工 商 管 理 学 院 公 共 管 理 学 院 法 学 院 社 会 学 院 外 国 语 学 院 中 国 现 当 代 史 世 界 中 古 史 世 界 近 现 代 史 文 化 遗 产 马 克 思 主 义 哲 学 国 际 政 治 科 学 社 会 主 义 马 克 思

第 2 節 介面佈局檔 第 1 項 說明 第 2 項 原始碼 第 3 節 主程式開發 第 1 項 主程式 - 基本設定 第 2 項 主程式 - 產生亂數 第 3 項 主程式 - 數字靠邊 數字加總 第 4 節 加入手

untitled

untitled

untitled

第1章 AutoCAD 2004与工程设计



untitled

第一章 Android 基礎知識 -UI 設計及語法應用 驗證 Activity A. 解題要項 熟悉新增 Activity 的關鍵步驟以及在清單檔案內的註冊方式 熟悉 Activity 的切換方法與參數傳遞的技巧 熟悉 Activity 回傳結果 ( 含資料 ) 的關鍵步驟與接

01

! " # " " $ % " " # # " $ " # " #! " $ "!" # "# # #! &$! ( % "!!! )$ % " (!!!! *$ ( % " (!!!! +$ % " #! $!, $ $ $ $ $ $ $, $ $ "--. %/ % $ %% " $ "--/

Microsoft Word - Chap16.doc

Java講義

// HDevelopTemplateWPF projects located under %HALCONEXAMPLES%\c# using System; using HalconDotNet; public partial class HDevelopExport public HTuple

互联网 + 创新创业实战系列教材 实战案例教程 钟元生赵圣鲁主编 江西高校出版社 二 O 一七年七月

Microsoft PowerPoint - Lab 3-1 Vehicular Navigation Systems.ppt [相容模式]

说 : 荀 子 极 偏 驳, 只 一 句 性 恶, 大 本 已 失 5 朱 熹 说 : 荀 扬 不 惟 说 性 不 是, 从 头 到 底 皆 不 识 6 采 取 的 都 是 这 种 理 论 框 架 另 一 种 理 论 框 架 始 于 20 世 纪 前 期, 这 便 是 诸 子 学 研 究 的 框 架

Introduction Android 应用开发课程介绍 本课程旨在通过 6 个基本任务和相关的知识点, 让学习者在短时间内通过任务驱动的方式快速学习掌握 Android 的基本编程 本在线教程与温州大学 SPOC 对接, 可在 SPOC 中观看具体的视频, 帮助完成实现各基本任务 本在线教程目前

基于Cortex-A8 Android&Linux系统与应用开发

IsPostBack 2

图形图像处理 (Photoshop CS6) [ pixel ] % % % % dpi/inch dpi 150dpi 300dpi 002

Microsoft Word - 第5章.doc

untitled

untitled

Microsoft Word - Chap04.doc

X713_CS_Book.book

Microsoft Word - 第5章.doc

H5 H6 H10 H12 H F1 3 1 F H2 H

对于部署 MOSS 工作流, 有下面这些步骤 1. 添加 DLL 文件到 GAC 中 2. 配置 feature.xml 和 workflow.xml 文件 3. 在服务器添加 Feature 文件夹, 复制相关文件 4. 利用 stsadm 命令部署并激活 Feature Step1 添加 DLL

安全注意事项 2. 设置对焦模式 3. 变焦 1. 安装和卸下镜头 4. 固定变焦环 1 2 CHI-2

資訊管理系 專題成果報告 行動 APP 製作 節奏遊戲 Rhythm Stars 學生 : 黃政皓 謝瑋良 謝政宏 楊啟杰 李皓揚 本成果報告書經審查及口試合格特此證明 考試委員 : 指導老

free hi-q recorder full version

第 1 章初识 Android 系统 Android 是 Google 于 2007 年 11 月 5 日发布基于 Linux 内核的移动软件, 主要使用于便携设备 该平台由操作系统 中间件 用户界面和应用软件组成, 是一个真正开放的移动开发平台 本章将介绍 Android 系统的发展 特点 应用程

信息

Microsoft Word - 第3章.doc

FireBase資料庫

Java講義

The Embedded computing platform

Contents 1 深 圳 大 学 经 济 学 院 学 生 代 表 大 会 章 程 2 2 优 秀 毕 业 生 评 选 细 则 7 3 议 事 规 则 8 i

FPGAs in Next Generation Wireless Networks WPChinese

Information for consent


Transcription:

单击以编辑母片标题样式 安卓系统 Android 的排版 授课老师 : 谢兆贤 2016/4/18 1

单击以编辑母片 Content 标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 2

单击以编辑母片知识点ㄧ标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 3

单击以编辑母片 LinearLayout 排标题样式版模式 q LinearLayout 范例 LinearLayout 标签是一种接口组件的编排方式, 顾名思义它就是依照线性次序由上往下逐一排列接口组件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width= match_parent" android:layout_height= match_parent > <TextView android:text=" 姓名 :" /> <EditText android:text=" 输入姓名 " /> <Button android:text=" 确定 " /> </LinearLayout>??? 4

单击以编辑母片 LinearLayout 排标题样式版模式 q 水平排列的 LinearLayout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width= match_parent" android:layout_height= match_parent" > <TextView android:layout_width="wrap_content" android:text=" 姓名 :" /> <EditText android:layout_width="wrap_content" android:text=" 输入姓名 " /> <Button android:layout_width="wrap_content" android:text=" 确定 " /> </LinearLayout>??? 5

单击以编辑母片 LinearLayout 排标题样式版模式 q 二层 LinearLayout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" > <LinearLayout android:orientation="horizontal android:background="#ffffff" > <TextView android:textcolor="#000000" android:text=" 姓名 :" /> <EditText android:text=" 输入姓名 " /> </LinearLayout> <Button android:text=" 确定 " /> </LinearLayout> 6

单击以编辑母片 LinearLayout 排标题样式版模式 q 使用二层 LinearLayout 的 婚姻建议 程序 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width= match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" > <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/promptsex" /> <Spinner android:id="@+id/spnsex" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawselectorontop="true" android:prompt="@string/spnsexprompt" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/promptage" /> <Spinner android:id="@+id/spnage" android:layout_width="match_parent " android:layout_height="wrap_content" android:drawselectorontop="true" android:prompt="@string/spnageprompt" /> </LinearLayout> ( 接下页 ) 7

单击以编辑母片 LinearLayout 排标题样式版模式 q 使用二层 LinearLayout 的 婚姻建议 程序 ( 接上页 ) <Button android:id="@+id/btndosug" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/promptbtndosug" android:paddingleft="20dp" android:paddingright="20dp" /> <TextView android:id="@+id/txtresult" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/sugresult" /> </LinearLayout> 8

单击以编辑母片知识点二标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 9

单击以编辑母片 TableLayout 排标题样式版模式 q TableLayout 范例 TableLayout 就是把接口组件依照表格的方式排列, 也就是由上往下一列接着一列, 而且前后每一个字段依序对齐 <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="400dp" android:layout_height="match_parent" android:layout_gravity="center_horizontal" > <TableRow> <TextView android:text=" 姓名 :"/> <TextView android:text=" 性别 :"/> <TextView android:text=" 生日 :"/> </TableRow> <TableRow> <EditText android:text=" 输入姓名 "/> <EditText android:text=" 输入性别 "/> <EditText android:text=" 输入生日 "/> </TableRow> <Button android:text=" 确定 "/> </TableLayout> 10

单击以编辑母片 TableLayout 排标题样式版模式 q 使用 TableLayout 的注意事项 1. 包裹在 TableRow 标签中的接口组件它的 android:layout_width 和 android:layout_height 属性都没有作用, 也就是说不管把它们的值设定为 match_parent 或是 wrap_content, 都一律使用 wrap_content 模式, 因此可以直接把这二个属性省略 2. 像是 android:backgroud 设定底色的属性 android:gravity 设定对齐方式的属性 和 android:layout_margin 设定组件的距离等类似功能的属性都可以用于 TableLayout 和 TableRow 卷标中, 例如可以在上面范例的第一个 TableRow 标签中加入 android:gravity= center_horizontal 就可以将第一列的接口组件做水平置中对齐 11

单击以编辑母片 TableLayout 排标题样式版模式 3. 如果 TableLayout 标签中的接口组件没有被包含在 TableRow 标签中, 则该组件会自成一列如上面范例的 Button 组件 4. 如果要让 TableRow 标签中的组件依比例使用整个 Table 的宽度, 可以藉助 android:layout_weight 属性, 它会将同一列组件所有的 weight 值加总后, 再依照每一个组件的 weight 值的比例计算所占的宽度 12

单击以编辑母片 TableLayout 排标题样式版模式 <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/and roid" android:layout_width="400dp" android:layout_height="match_parent" android:layout_gravity="center_horizontal" > <TableRow> <TextView android:text=" 姓名 :" </TableRow> android:layout_weight="1"/> <TextView android:text=" 性別 :" android:layout_weight="1"/> <TextView android:text=" 生日 :" android:layout_weight="1"/> 13

单击以编辑母片 TableLayout 排标题样式版模式 5. 如果希望 TableLayout 标签中的 TableRow 内组件可以错开如下的画面, 可以在 TableLayout 标签中再增加一个 TableLayout 标签 14

单击以编辑母片 TableLayout 排标题样式版模式 <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" > <TableLayout > <TableRow> <TextView android:text=" 姓名 :"/> </TableRow> <TableRow> <EditText android:text=" 输入姓名 "/> </TableRow> </TableLayout> <TableRow> </TableRow> <TableRow> </TableRow> <Button android:text=" 确定 "/> </TableLayout> 15

单击以编辑母片 TableLayout 排 <TableLayout 标题样式版模式 <?xml version="1.0" encoding="utf-8"?> > <TableRow> <TextView android:layout_width= match_parent" android:layout_height="wrap_content" android:text="@string/promptsex /> <RadioGroup <RadioButton android:id="@+id/radbtnmale" android:text="@string/male" /> </RadioGroup> </TableRow> <RadioButton android:id="@+id/radbtnfemale" android:text="@string/female" /> <TableRow> <TextView android:layout_width= match_parent" android:layout_height="wrap_content" android:text="@string/age" /> <RadioGroup <RadioButton android:id="@+id/radbtnagerange1 /> <RadioButton android:id="@+id/radbtnagerange2 /> <RadioButton android:id="@+id/radbtnagerange3 /> </RadioGroup> </TableRow> <Button android:id="@+id/btnok" android:layout_width= match_parent" android:layout_height="wrap_content" android:text="@string/btn_ok /> <TextView android:id="@+id/txtr" android:layout_width= match_parent" android:layout_height="wrap_content" /> </TableLayout> 16

单击以编辑母片 TableLayout 排标题样式版模式 17

单击以编辑母片知识点三标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 18

单击以编辑母片 RelativeLayout 标题样式排版模式 q RelativeLayout 范例 RelativeLayout 是靠指定接口组件之间的相对位置关系来决定它们的排列方式, 为了能够辨识每一个组件, 我们必须指定每一个组件的 id 名称 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout > <TextView android:id="@+id/txt1 /> <TextView android:id="@+id/txt2" android:layout_torightof="@id/txt1"/> <EditText android:id="@+id/edt1" android:layout_below="@id/txt1"/> <EditText android:id="@+id/edt2" android:layout_torightof="@id/edt1"/> <Button android:id="@+id/btn1" android:layout_below="@id/edt1"/> </RelativeLayout> 19?????

单击以编辑母片 RelativeLayout 标题样式排版模式 q RelativeLayout 范例 ( 加上 align 属性 ) <?xml version="1.0" encoding="utf-8"?> <RelativeLayout > <TextView android:id="@+id/txt1" /> <TextView android:id="@+id/txt2 android:layout_torightof="@id/txt1"/> <EditText android:id="@+id/edt1" android:layout_below="@id/txt1"/> <EditText android:id="@+id/edt2" android:layout_torightof="@id/edt1 android:layout_aligntop="@id/edt1"/> <Button android:id="@+id/btn1" android:layout_below="@id/edt1"/> </RelativeLayout> 20???

单击以编辑母片 RelativeLayout 标题样式排版模式 q RelativeLayout 相关属性 属性类别属性名称属性值说明 指定相对位置 指定对齐方式 layout_toleftof id/ 某一个接口组件 id 名称 将接口组件置于指定接口组件的左边 layout_torightof id/ 某一个接口组件 id 名称 将接口组件置于指定接口组件的右边 layout_above id/ 某一个接口组件 id 名称 将接口组件置于指定接口组件的上方 layout_below id/ 某一个接口组件 id 名称 将接口组件置于指定接口组件的下方 layout_alignleft id/ 某一个接口组件 id 名称 将接口组件和指定接口组件的左边对齐 layout_alignright id/ 某一个接口组件 id 名称 将接口组件和指定接口组件的右边对齐 layout_aligntop id/ 某一个接口组件 id 名称 将接口组件和指定接口组件的上缘对齐 layout_alignbottom id/ 某一个接口组件 id 名称 将接口组件和指定接口组件的下缘对齐 layout_alignbaseline id/ 某一个接口组件 id 名称 将接口组件和指定接口组件的中心线对齐 layout_alignparentleft true 或 false 将接口组件对齐它所在的外框左边 layout_alignparentright true 或 false 将接口组件对齐它所在的外框右边 layout_alignparenttop true 或 false 将接口组件对齐它所在的外框上缘 layout_alignparentbottom true 或 false 21 将接口组件对齐它所在的外框下 缘

单击以编辑母片 RelativeLayout 标题样式排版模式 q 使用 RelativeLayout 的注意事项 最先宣告的接口组件会放在屏幕的左上方, 如果后面宣告的接口组件指定的位置是在第一个接口组件的左边或是上方, 那么就会看不到这个接口组件 例如以下范例将看不到 edt1 组件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout > <TextView android:id="@+id/txt1 /> <EditText android:id="@+id/edt1 android:layout_above="@id/txt1"/>... </RelativeLayout> 22

单击以编辑母片 RelativeLayout 标题样式排版模式 q 使用 RelativeLayout 的注意事项 这个问题有二种解决方法 可以利用 android:layout_center 相关的属性把第一个宣告的组件往屏幕的右下方移动 调整接口组件宣告的次序, 例如 : 把范例中的 edt1 组件放到前面宣告, 然后指定 txt1 组件置于 edt1 的下方 23

单击以编辑母片 RelativeLayout 标题样式排版模式 q RelativeLayout 的成果 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout > <TextView android:id="@+id/txt1" /> <EditText android:id="@+id/edt1" android:layout_below="@id/txt1"/> <EditText android:id="@+id/edt2" android:layout_torightof="@id/edt1" android:layout_aligntop="@id/edt1"/> <TextView android:id="@+id/txt2" android:layout_above="@id/edt2" android:layout_alignleft="@id/edt2"/> <Button android:id="@+id/btn1" android:layout_below="@id/edt1"/> </RelativeLayout> 24???

单击以编辑母片 RelativeLayout 标题样式排版模式 q 使用 RelativeLayout 的 计算机猜拳游戏 程序 这个电脑猜拳游戏, 必须考虑下列几件事 我们必须设计一个简单清楚的接口, 让玩家可以任意选择出剪刀 石头或是布 电脑必须能够自行决定出拳, 而且没有规则性, 否则玩家便有可能破解 游戏进行的画面必须简单, 而且易于了解 25

单击以编辑母片 RelativeLayout 标题样式排版模式 q 使用 随机数 功能 所谓 随机数 是一群出现次序不规则的数, 也就是随机产生的数字 随机数经常用来模拟一些随机的结果, 像是游戏常用的丢骰子 在 Java 程序中可以呼叫 Math.random() 方法产生一个介于 0 和 1 之间的小数 ( 可能是 0, 但是永远小于 1) 我们可以利用乘法把这个小数放大再转换成整数型态, 例如 : int iran = (int)(math.random()*6 + 1); iran 的值永远是 1 ~ 6 的整数其中之一, 在猜拳游戏中, 我们可以用 1 2 3 分别表示剪刀 石头 和布, 因此我们需要的是 1 ~ 3 之间的整数, 那么只要将上面公式中的 6 改成 3 即可 26

单击以编辑母片知识点四标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 27

单击以编辑母片 AbsoluteLayout 标题样式排版模式 q 显示范例 28

单击以编辑母片 AbsoluteLayout 标题样式排版模式 q 绝对布局或坐标布局 优点 弹性大 缺点 复杂 不同尺寸手机显示不同结果 维护困难 q 注意事项 原点为屏幕坐上角 精确计算视图像素大小 q 布局设置 可视化软件 (DroidDraw) Android:layout_x Android:layout_y 29

单击以编辑母片 AbsoluteLayout 标题样式排版模式 q 范例 Ch2_5 的 main.xml <?xml version="1.0" encoding="utf-8"?> <!-- 绝对布局, 此种布局方式由于对屏幕分辨率自适应的能力较弱, 在实际的开发中很少使用 --> <AbsoluteLayout android:id="@+id/widget27" android:layout_width="fill_parent android:layout_height="fill_parent xmlns:android="http://schemas.android.com/ apk/res/android"> <!-- ImageButton 图片按钮, 其中 android:layout_x, android:layout_y 表示在屏幕 x,y 上的坐标值 -- > <ImageButton android:id="@+id/imgbutton" android:layout_width="wrap_content android:layout_height="wrap_content" android:layout_x="130px" android:layout_y="92px" android:src="@drawable/icon"> </ImageButton> <TextView android:layout_width="wrap_content android:layout_height="wrap_content" android:text=" 这是绝对布局的演示 " android:layout_x="120px" android:layout_y="192px"> </TextView> <AnalogClock android:id="@+id/analogclock" android:layout_width="wrap_content android:layout_height="wrap_content" android:layout_x="80px" android:layout_y="272px"> </AnalogClock> </AbsoluteLayout> 30

单击以编辑母片知识点五标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 31

单击以编辑母片 FrameLayout 排标题样式版模式 q 显示范例 32

单击以编辑母片 FrameLayout 排标题样式版模式 q 单祯布局或框架布局 固定到屏幕左上角 一层覆盖一层, 後者覆蓋前者 33

单击以编辑母片 FrameLayout 排标题样式版模式 <?xml version="1.0" encoding="utf-8"?> <!-- 单帧布局 --> q 范例 Ch2_4 的 main.xml <FrameLayout xmlns:android="http://schemas.android.com/ apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- 图片控件, 通过 android:src 属性设置图片控件中要显示的图片 图片一般位于 drawable 文件夹下 --> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/big"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/medium"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/small"/> </FrameLayout> 34

单击以编辑母片知识点六标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 35

单击以编辑母片 GridLayout 排版标题样式模式 q 显示范例 36

单击以编辑母片 GridLayout 排版标题样式模式 q 网格布局 网格方式布局子组件 子组件 X 和 Y 轴自动对齐 37

单击以编辑母片 GridLayout 排版标题样式模式 q 范例 ch03_3d7_gridlayout 的 activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/ apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ededed" > <GridLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ededed" android:columncount="4" android:orientation="horizontal" android:rowcount="3" > <Button android:layout_columnspan="2" android:layout_gravity="fill" android:text="1.1" /> <Button android:text="1.2" /> <Button android:layout_gravity="fill" android:layout_rowspan="2" android:text="1.3" /> <Button android:layout_columnspan="3" android:layout_gravity="fill" android:text="2.1" /> <Button android:text="3.1" /> <Button android:text="3.2" /> <Button android:text="3.3" /> <Button android:text="3.4" /> </GridLayout> </LinearLayout> 38

单击以编辑母片知识点七标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 39

单击以编辑母片 TabWidget 切換标题样式卡 q 显示范例 40

单击以编辑母片 TabWidget 切換标题样式卡 q 何谓切换卡 通过多个卷标切换已显示不同的内容 q 何谓 TabHost 存放多个 Tab 标签的容器, 每个 Tab 都可以对应自己的布局 q TabHost 做法 gettabhost() 方法获取 TabHost 的对象 addtab() 方法向 TabHost 添加 Tab setontabchangedlistener() 监听捕获的信息 41

单击以编辑母片 TabWidget 切換标题样式卡 q TabHost 使用的方法有以下两种 系统自带写好的 TabHost 以及继承 TabActivity 类 TabHost 的 ID 为 @android:id/tabhost TabWidget 的 ID 为 @android:id/tabs FrameLayout 的 ID 为 @android:id/tabcontent 定义自己的 TabHost, 不用继承 TabActivity TabHost 的 ID 可以自己定义 TabWidget 的 ID 为 @android:id/tabs FrameLayout 的 ID 为 @android:id/tabcontent 42

单击以编辑母片知识点八标题样式 LinearLayout 排版模式 TableLayout 排版模式 RelativeLayout 排版模式 AbsoluteLayout 排版模式 FrameLayout 排版模式 GridLayout 排版模式 TabWidget 切換卡 Lab 5 43

单击以编辑母片 Lab 5 标题样式 q 电脑猜拳 游戏程序的档案说明 单元 19 的程序码 界面布局檔 字串资源文件 程序檔 完成本题, 可得 1% 改成简体字改成简体字改成简体字改成简体字改成简体字 44 改成简体字

单击以编辑母片 Lab 5 标题样式 q 修改 计算机猜拳游戏 修改后需要考虑下列几件事 设计一个简单清楚的接口, 让玩家可以任意选择出将 士 象 车 马 炮 或卒 计算机 / 玩家猜拳失败后将不能在出该拳, 直到一方全部都不能在出拳后宣布最后的胜利 电脑必须能够自行决定出拳, 而且没有规则性, 否则玩家便有可能破解 完成本题, 可得 4% 卒 将 车 马 士 象 马 炮 45

单击以编辑母片标题样式 46