安卓计算器开发实验报告
嵌入式WebOS应用开发
实验报告
实验名称:使用An droid Developer SDK开发应用程序
专业:_________________________
姓名:__________________________________
班级:_______________________________
学号:______________________________
一、作品的运行环境及安卓SDK基础操作
SDK An droid Developer 是一款在windows系统上运行的针对
An droid应用开发的谷歌官方软件(需要JAVA环境支持)。
1、导入工程
2、建立虚拟机
在运行虚拟机是为保证机器的顺畅运行建议选择分辨率较低的虚拟机,但是其RAM最好设为512MB因为部分程序如果调用资源过大会导致虚拟机无法运行。
3、虚拟机界面
二、作品介绍
我的应用是一个计算器。能实现包括小数的加减乘除运算,结果过大会自动用科学记数法表示,另外还有退格跟清屏功能键。
加应用图标 1.首先在我的桌面上添加你应 用的图标以及文字,双击图标后
项中自行进行挑选;
也可以添加自己的图片,
只要将图片放到对应的
文件夹之下在刷新就可 以,但不建议放分辨率 过高图片可能会出现超 出界面的等错误。
要在xml 界面中添加排版:
xml 代码首末的 格式较为自由可以直接在
界面中拖动图标位置以及修改大小,而其他layout 则更会自动排列, 各有优劣。
三、 编程以及运行调试
(一)、在MyDesktop 主界面中添 fin^_ok,prig 世IF it launchiWipng
32E img'O.png jdE im^il.png] 3E
img?.pHg 血 imql.pngi 32E img4.png 血 im^S.pngi Tn? imgg.png JJL -mgT.pngj ..1. imy^.png
..1. uiHiprxg
就可以看见对应的代码, 可直接
在代码中进行修改图片文字的 大小颜色等等。
以下是对应图像图标的代码
图片可以在左侧的选
(二)、在 res/layout 目录下新建.xml 文件,由于计算器的按钮很多, TIF charfrc
起 ch^tfrorn_bg_ipTW5&d !S'.pflg
~l <+i?,kbnif^M
口
.股 ch?kbojco#f bsckgrourid^na SE
chfkb rn (」]n.hewlcgin 口unci 岱n 评 弧 tlwr^na TTF de^ r o 1 .pnq
(三)、在src/目录下新建.java 文件,计算器的按钮算法等都在此实 现。
(三)、声明工程名
1、在应用中有三处需要声明,首先是在
2、然后是在
四、代码展示
(一)、.xml 界面代码
v? xml version ="" encoding ="utf-8" ?> an droid:layout_width ="fill_pare nt"
vTableLayout
an droid:id
= "@+id/tableLayout1" an droid:layout_width
an droid:layout_height an droid:collapseColu mns vTableRow
TableRow > vTableRow
an droid:id ="@+id/tableRow1"
an droid:layout_width ="fill_pare nt" an droid:layout_height ="fill_pare nt"
< Butt on
an droid:id ="@+id/bt_7" android:layout width
="80px"
an droid:layout_height = "fill_pare nt" an droid:orie ntatio n 「vertical" > ="match_pare nt" = "wrap_c on te nt" ="4" > an droid:id an droid:layout_width an droid:layout_height an droid:id "@+id/tableRow_et" ="@+id/et" an droid:layout_width an droid:layout_height an droid:layout_spa n an droid:focusable an droid:gravity an droid:i nputType an droid:s in gleL ine EditText > = "fill_pare nt" ="fill_pare nt" = "fill_pare nt" ="fill_pare nt' "4" = "false" = "right" = "text" = "true" > an droid:layout height ="80px" an droid:text ="7" /> < Butt on an droid:id ="@+id/bt_8" an droid:layout width ="80px" an droid:layout height ="80px" an droid:text ="8" /> < Butt on an droid:id ="@+id/bt_9" an droid:layout_width = "1px" an droid:layout height ="80px" an droid:text ="9" /> < Butt on an droid:id ="@+id/bt_back" an droid:layout width ="80px" an droid:layout height ="80px" an droid:text ="back" /> TableRow > an droid:id ="@+id/tableRow2" an droid:layout_width ="fill. _paren t" an droid:layout_height ="fill_pare nt" < Butt on an droid:id ="@+id/bt_4" an droid:layout width ="80px" android:layout height ="80px" an droid:text ="4" /> < Butt on an droid:id ="@+id/bt_5" an droid:layout width ="80px" android:layout height ="80px" an droid:text ="5" /> < Butt on an droid:id ="@+id/bt_6" an droid:layout width ="80px" android:layout height ="80px" an droid:text ="6" /> < Butt on an droid:id ="@+id/bt_divide" android:layout width ="80px" android:layout height ="80px" an droid:text ="/" /> TableRow > vTableRow an droid:id ="@+id/tableRow3" an droid:layout_width ="fill_pare nt" an droid:layout_height ="fill_pare nt" < Butt on an droid:id ="@+id/bt_1" an droid:layout width ="80px" an droid:layout height ="80px" an droid:text _="1" /> < Butt on an droid:id ="@+id/bt_2" an droid:layout width ="80px" an droid:layout height ="80px" an droid:text 三"2" /> < Butt on an droid:id ="@+id/bt_3" an droid:layout width ="80px" an droid:layout height ="80px" an droid:text _="3" /> < Butt on an droid:id ="@+id/bt_multiply" an droid:layout width ="80px" an droid:layout height ="80px" an droid:text 三'*" /> TableRow > vTableRow an droid:id ="@+id/tableRow4" an droid:layout_width ="fill_pare nt" an droid:layout_height ="fill_pare nt" < Butt on an droid:id ="@+id/bt_0" android:layout width ="50px" an droid:layout height ="80px" an droid:text 三"0" /> < Butt on an droid:id ="@+id/bt_po in t" android:layout width ="50px" an droid:layout height ="80px" an droid:text _="." /> < Butt on an droid:id ="@+id/bt_add" android:layout width ="50px" an droid:layout height ="80px" an droid:text _="+" /> < Button an droid:id ="@+id/bt_sub" an droid:layout width ="50px" an droid:layout height ="80px" an droid:text 二"-" /> TableRow > vTableRow an droid:id ="@+id/tableRow4" an droid:layout_width ="fill_pare nt" an droid:layout_height ="fill_pare nt" > < Butt on an droid:id ="@+id/bt_equal" an droid:layout_width ="fill_pare nt" an droid:layout_height ="fill_pare nt" an droid:layout_spa n ="3" an droid:text ="=" /> < Butt on an droid:id ="@+id/bt_clear" an droid:layout width ="50px" an droid:layout height ="80px" an droid:text ="clear" /> TableRow > TableLayout > LinearLayout > (二)、.java功能代码 import class fffActivity exte nds Activity { private Butt on bt_1; private Butt on bt_2; private Butt on bt_3; private Butt on bt_4; private Butt on bt_5; private Butt on bt_6; private Butt on bt_7; private Butt on bt_8; private Butt on bt_9; private Butt on bt_0; private Butt on bt_add; private Butt on bt_sub;; flag = false; } } }); (n ew On ClickListe ner() @Override public void onClick(View v) { if () != 0) { { () - 1); ()); } } }); (new OnClickListener() { @Override public void onClick(View v) { str_oper = "+"; if (!() == "")) { num1 += ()); str_display = new StringBuffer(""); } if (!(str_result == null)) { num1 = (str_result); str_result = null; } (num1)); flag = true; } }); (new OnClickListener() { @Override public void onClick(View v) { str_oper = "-"; if (!b_sub && !() == "")) { num1 = ()); (num1)); str_display = new StringBuffer(""); b_sub = true; } else