安卓计算器开发实验报告文档格式.docx

上传人:b****5 文档编号:18694742 上传时间:2022-12-31 格式:DOCX 页数:25 大小:519.08KB
下载 相关 举报
安卓计算器开发实验报告文档格式.docx_第1页
第1页 / 共25页
安卓计算器开发实验报告文档格式.docx_第2页
第2页 / 共25页
安卓计算器开发实验报告文档格式.docx_第3页
第3页 / 共25页
安卓计算器开发实验报告文档格式.docx_第4页
第4页 / 共25页
安卓计算器开发实验报告文档格式.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

安卓计算器开发实验报告文档格式.docx

《安卓计算器开发实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《安卓计算器开发实验报告文档格式.docx(25页珍藏版)》请在冰豆网上搜索。

安卓计算器开发实验报告文档格式.docx

(一)、在MyDesktop主界面中添加应用图标

1.首先在我的桌面上添加你应用的图标以及文字,双击图标后就可以看见对应的代码,可直接在代码中进行修改图片文字的大小颜色等等。

以下是对应图像图标的代码

图片可以在左侧的选

项中自行进行挑选;

也可以添加自己的图片,

只要将图片放到对应的

文件夹之下在刷新就可

以,但不建议放分辨率

过高图片可能会出现超

出界面的等错误。

(二)、在res/layout目录下新建.xml文件,由于计算器的按钮很多,要在xml界面中添加排版:

xml代码首末的<

/AbsoluteLayout>

格式较为自由可以直接在界面中拖动图标位置以及修改大小,而其他layout则更会自动排列,各有优劣。

(三)、在src/weibo.test.ui目录下新建.java文件,计算器的按钮算法等都在此实现。

(三)、声明工程名

1、在应用中有三处需要声明,首先是在AndroidManifest.xml

2、然后是在MainActivity.java

四、代码展示

(一)、.xml界面代码

<

?

xmlversion="

1.0"

encoding="

utf-8"

>

LinearLayoutxmlns:

android="

android:

layout_width="

fill_parent"

layout_height="

orientation="

vertical"

>

<

TableLayout

id="

@+id/tableLayout1"

match_parent"

wrap_content"

collapseColumns="

4"

TableRow

@+id/tableRow_et"

EditText

@+id/et"

layout_span="

focusable="

false"

gravity="

right"

inputType="

text"

singleLine="

true"

/EditText>

/TableRow>

@+id/tableRow1"

Button

@+id/bt_7"

80px"

text="

7"

/>

@+id/bt_8"

8"

@+id/bt_9"

1px"

9"

@+id/bt_back"

back"

@+id/tableRow2"

@+id/bt_4"

@+id/bt_5"

5"

@+id/bt_6"

6"

@+id/bt_divide"

/"

@+id/tableRow3"

@+id/bt_1"

1"

@+id/bt_2"

2"

@+id/bt_3"

3"

@+id/bt_multiply"

*"

@+id/tableRow4"

@+id/bt_0"

50px"

0"

@+id/bt_point"

."

@+id/bt_add"

+"

@+id/bt_sub"

-"

@+id/bt_equal"

="

@+id/bt_clear"

clear"

/TableLayout>

/LinearLayout>

(二)、.java功能代码

packageweibo.test.ui;

importjava.util.ArrayList;

importjava.util.List;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.EditText;

importandroid.widget.Toast;

importweibo.lixiaodaoaaa.ui.R;

importandroid.content.Intent;

importandroid.content.pm.PackageManager;

importandroid.view.KeyEvent;

importandroid.widget.ListView;

importcom.zsy.flipper.AppInfUtil;

importcom.zsy.flipper.AppInfo;

publicclassfffActivityextendsActivity

{

privateButtonbt_1;

privateButtonbt_2;

privateButtonbt_3;

privateButtonbt_4;

privateButtonbt_5;

privateButtonbt_6;

privateButtonbt_7;

privateButtonbt_8;

privateButtonbt_9;

privateButtonbt_0;

privateButtonbt_add;

privateButtonbt_sub;

//减

privateButtonbt_multiply;

//乘

privateButtonbt_divide;

//除

privateButtonbt_back;

privateButtonbt_equal;

//等于

privateButtonbt_point;

//点

privateButtonbt_clear;

//清除

privateEditTextet_play;

//显示

privateStringstr_oper="

;

//运算符

privateStringBufferstr_display=newStringBuffer();

privateStringstr_result;

//结果显示

privatedoublenum1;

privatedoublenum2;

privatebooleanflag=true;

//小数点个数开关控制;

privatebooleanb_sub,b_mul,b_div;

//运算符开关控制

@Override

publicvoidonCreate(BundlesavedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_fff);

bt_0=(Button)findViewById(R.id.bt_0);

bt_1=(Button)findViewById(R.id.bt_1);

bt_2=(Button)findViewById(R.id.bt_2);

bt_3=(Button)findViewById(R.id.bt_3);

bt_4=(Button)findViewById(R.id.bt_4);

bt_5=(Button)findViewById(R.id.bt_5);

bt_6=(Button)findViewById(R.id.bt_6);

bt_7=(Button)findViewById(R.id.bt_7);

bt_8=(Button)findViewById(R.id.bt_8);

bt_9=(Button)findViewById(R.id.bt_9);

bt_add=(Button)findViewById(R.id.bt_add);

bt_sub=(Button)findViewById(R.id.bt_sub);

bt_multiply=(Button)findViewById(R.id.bt_multiply);

bt_divide=(Button)findViewById(R.id.bt_divide);

bt_back=(Button)findViewById(R.id.bt_back);

bt_equal=(Button)findViewById(R.id.bt_equal);

bt_point=(Button)findViewById(R.id.bt_point);

bt_clear=(Button)findViewById(R.id.bt_clear);

et_play=(EditText)findViewById(R.id.et);

et_play.setText("

);

bt_0.setOnClickListener(newOnClickListener()

{

@Override

publicvoidonClick(Viewv)

{

str_display.append("

et_play.setText(str_display.toString());

}

});

bt_1.setOnClickListener(newOnClickListener()

bt_2.setOnClickListener(newOnClickListener()

bt_3.setOnClickListener(newOnClickListener()

bt_4.setOnClickListener(newOnClickListener()

bt_5.setOnClickListener(newOnClickListener()

bt_6.setOnClickListener(newOnClickListener()

bt_7.setOnClickListener(newOnClickListener()

bt_8.setOnClickListener(newOnClickListener()

bt_9.setOnClickListener(newOnClickListener()

bt_point.setOnClickListener(newOnClickListener()

if(flag)

{

str_display.append("

flag=false;

}

bt_back.setOnClickListener(newOnClickListener()

if(str_display.length()!

=0)

str_display.deleteCharAt(str_display.length()-1);

et_play.setText(str_display.toString());

bt_add.setOnClickListener(newOnClickListener()

str_oper="

if(!

(str_display.toString()=="

"

))

num1+=Double.parseDouble(str_display.toString());

str_display=newStringBuffer("

(str_result==null))

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1