魯苓茜 安卓實(shí)訓(xùn)報(bào)告_第1頁
魯苓茜 安卓實(shí)訓(xùn)報(bào)告_第2頁
魯苓茜 安卓實(shí)訓(xùn)報(bào)告_第3頁
魯苓茜 安卓實(shí)訓(xùn)報(bào)告_第4頁
魯苓茜 安卓實(shí)訓(xùn)報(bào)告_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、綿陽師范學(xué)院Mianyang Normal University安卓實(shí)訓(xùn)報(bào)告題 目: BMI體重指數(shù)計(jì)算器 班 級(jí): 13080404 學(xué) 號(hào): 1308040429 姓 名: 魯苓茜 綿陽師范學(xué)院 信息工程學(xué)院 計(jì)算機(jī)科學(xué)與技術(shù)2016年4月21日目 錄一、項(xiàng)目背景3二、項(xiàng)目目的3三、項(xiàng)目功能3四、項(xiàng)目開發(fā)環(huán)境4五、主要代碼及截圖4六、心得體會(huì)9一、 項(xiàng)目背景 現(xiàn)代社會(huì)的人越來越關(guān)注自己的身體健康,BMI指數(shù)就可以根據(jù)自己的體重跟身高計(jì)算出一個(gè)指數(shù),然后根據(jù)BMI指數(shù)查詢BMI中國參考標(biāo)準(zhǔn),即可知道自己的身體是偏胖,偏瘦還是適中。然后可以及時(shí)調(diào)整自己的飲食,保持身體的健康。然而很多BMI的查

2、詢都是PC端的,現(xiàn)在是一個(gè)智能手機(jī)流行的時(shí)代,人們幾乎都離不開手機(jī)了。所以做一個(gè)手機(jī)端的BMI軟件是很有必要的,可以使人們更加方便地查詢自己的BMI指數(shù),及時(shí)了解自己的健康狀況。二、項(xiàng)目目的當(dāng)今是一個(gè)智能手機(jī)的年代,幾乎人人都有一部智能手機(jī),我覺得與其做一個(gè)手機(jī)游戲軟件,還不如做一個(gè)生活軟件,為大家的生活提供方便。這個(gè)BMI軟件是很方便的,可以隨時(shí)隨地的查詢自己的BMI指數(shù),及時(shí)的了解自己的健康狀況。三、項(xiàng)目功能1. 輸入體重跟身高2. 得到BMI指數(shù)3. 即可知道自己的身材是否合理四、項(xiàng)目開發(fā)環(huán)境計(jì)算機(jī)環(huán)境:Windows7編譯器:eclipse安卓虛擬器:夜神安卓虛擬器語言:JAVA五、主

3、要代碼及截圖截圖:代碼:activity_main.xml<RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" android:background="drawable/bmi_bj" tools:context=".MainActivity" > <TextView android:id=&qu

4、ot;+id/tv_height" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="cm(厘米)" android:layout_marginTop="80dp" android:layout_marginLeft="40dp" android:textSize="20sp" /> <TextView android:id=&qu

5、ot;+id/tv_weight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="kg(千克)" android:layout_below="+id/tv_height" android:layout_marginTop="10dp" android:layout_marginLeft="40dp" android:textSize=&qu

6、ot;20sp" /> <!-hint:暗示 -> <!-layout_alignBaseline:同一行顯示 -> <EditText android:id="+id/ed_weight" android:layout_width="160dp" android:layout_height="wrap_content" android:layout_toRightOf="+id/tv_weight" android:layout_alignBaseline="

7、;+id/tv_weight" android:hint="請(qǐng)輸入體重" android:inputType="number" /> <EditText android:id="+id/ed_height" android:layout_width="160dp" android:layout_height="wrap_content" android:layout_alignTop="+id/tv_height" android:layout_toRi

8、ghtOf="+id/tv_height" android:hint="請(qǐng)輸入身高" android:inputType="number"> </EditText> <RadioGroup android:id="+id/rg_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="+id/tv_

9、weight" android:layout_centerHorizontal="true" android:orientation="horizontal" android:layout_marginTop="20dp"> <RadioButton android:id="+id/boy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:c

10、hecked="true" android:text="男"/> <RadioButton android:id="+id/girl" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女"/> </RadioGroup> <Button android:id="+id/count" android

11、:layout_width="240dp" android:layout_height="wrap_content" android:text="計(jì)算BMI" android:background="drawable/ib_btn" android:layout_centerHorizontal="true" android:layout_below="+id/rg_group" android:layout_marginTop="20dp"/> &

12、lt;Button android:id="+id/reset" android:layout_width="240dp" android:layout_height="wrap_content" android:text="重置BMI" android:background="drawable/ib_btn" android:layout_centerHorizontal="true" android:layout_below="+id/count" a

13、ndroid:layout_marginTop="20dp"/></RelativeLayout>MainActivitypackage com.example.bmi;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.wid

14、get.EditText;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.RadioGroup.OnCheckedChangeListener;import android.widget.Toast;public class MainActivity extends Activity /快捷方式:Ctrl+1 private EditText height;private EditText weight;private RadioGroup group;privat

15、e String sex="男"Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); /設(shè)置顯示的布局 setContentView(R.layout.activity_main); height = (EditText) findViewById(R.id.ed_height); weight = (EditText) findViewById(R.id.ed_weight); group = (RadioGroup) findView

16、ById(R.id.rd_group); /增加選中狀態(tài)監(jiān)聽 group.setOnCheckedChangeListener(new OnCheckedChangeListener()Overridepublic void onCheckedChanged(RadioGroup arg0, int CheckedID) / TODO Auto-generated method stubswitch (CheckedID) case R.id.boy:sex="男"break;case R.id.girl:sex="女"break;default:bre

17、ak; ); Button count = (Button) findViewById(R.id.count); Button reset = (Button) findViewById(R.id.reset); /setOnClickListener:設(shè)置Button的點(diǎn)擊事件 count.setOnClickListener(new MyOnClick(); reset.setOnClickListener(new MyOnClick(); /* * 1、創(chuàng)建一個(gè)內(nèi)部類,實(shí)現(xiàn)OnClickListener接口 2、通過view.getId()得到點(diǎn)擊Button的ID 3、通過switch

18、判斷兩個(gè)Button的ID,去吐司 */ class MyOnClick implements OnClickListenerOverridepublic void onClick(View view) switch (view.getId()case R.id.count:if (height.getText().toString().trim().length()=0) height.setError("身高輸入不對(duì)");return;if (weight.getText().toString().trim().length()=0) weight.setError(&

19、quot;體重輸入不對(duì)");return;/1、獲取輸入框的值/身高的值double d_height = Double.parseDouble(height.getText().toString()/100;/體重的值double d_weight = Double.parseDouble(weight.getText().toString();/計(jì)算BMI的公式:體重/(身高*身高)double BMI = d_weight/(d_height*d_height);/吐一個(gè)司/Toast.makeText(MainActivity.this, "你的身高是"+

20、d_height+"n"+"你的體重是"+d_weight+"n"+"你的BMI是"+BMI, 1).show();/intent相當(dāng)于信使:實(shí)現(xiàn)兩個(gè)進(jìn)程之間的跳轉(zhuǎn)Intent intent = new Intent(MainActivity.this, NewActivity.class);intent.putExtra("BMI", BMI);intent.putExtra("height", d_height);intent.putExtra("sex&quo

21、t;, sex);/開始一個(gè)新的ActivitystartActivity(intent);break;case R.id.reset:/設(shè)置身高體重為nullheight.setText("");weight.setText("");/設(shè)置RadioButton的選中狀態(tài)RadioButton boy = (RadioButton) findViewById(R.id.boy);boy.setChecked(true);/吐一個(gè)司Toast.makeText(MainActivity.this, "你重置了BMI", 1).show

22、();break;default:break; new_activity.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="

23、;drawable/bmi_bj"> <ImageView android:id="+id/img_photo" android:layout_width="match_parent" android:layout_height="200dp" android:layout_marginTop="20dp" android:src="drawable/bmi_1" /> <TextView android:id="+id/tv_bmi" an

24、droid:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center_horizontal" android:text="您的BMI的值:n21.1" android:textSize="20sp" /> <TextView android:id="+id/tv_statu

25、s" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center_horizontal" android:text="您的健康狀態(tài)處于:n 偏瘦" android:textSize="20sp" /> <TextView android:id="+i

26、d/tv_weight" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center_horizontal" android:text="您的體重應(yīng)該保持在:n 55kg-80kg" android:textSize="20sp" /></LinearLayo

27、ut>NewActivity:package com.example.bmi;import java.text.DecimalFormat;import android.app.Activity;import android.content.Intent;import android.graphics.Color;import android.os.Bundle;import android.widget.ImageView;import android.widget.TextView;public class NewActivity extends Activity private d

28、ouble d_BMI;private double d_height;private String sex;protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); /設(shè)置顯示的布局 setContentView(R.layout.new_activity); Intents(); InitView(); private void InitView() / TODO Auto-generated method stub/數(shù)據(jù)類型格式:保留兩位小數(shù)DecimalFormat mf

29、 = new DecimalFormat("#0.00");String m_BMI = mf.format(d_BMI);TextView bmi =(TextView) findViewById(R.id.tv_bmi); bmi.setText("您的BMI的值:n"+m_BMI); double min = 18* (d_height*d_height); double max = 22* (d_height*d_height); TextView weight = (TextView) findViewById(R.id.tv_weight);

30、 weight.setText("您的體重應(yīng)該保持在:n "+mf.format(min)+"kg"+"-"+mf.format(max)+"kg"); ImageView photo = (ImageView) findViewById(R.id.img_photo); TextView status = (TextView) findViewById(R.id.tv_status); if (sex.equals("男") if (d_BMI<18) photo.setImageRes

31、ource(R.drawable.bmi_1); status.setText("您的健康狀態(tài)處于:n 偏瘦"); status.setTextColor(Color.BLUE);else if (d_BMI>=18 && d_BMI<22) photo.setImageResource(R.drawable.bmi_2); status.setText("您的健康狀態(tài)處于:n 正常"); status.setTextColor(Color.GREEN);else if (d_BMI>=22 && d_B

32、MI<25) photo.setImageResource(R.drawable.bmi_3); status.setText("您的健康狀態(tài)處于:n 偏胖"); status.setTextColor(Color.YELLOW);else photo.setImageResource(R.drawable.bmi_4); status.setText("您的健康狀態(tài)處于:n 太胖"); status.setTextColor(Color.RED);else if (d_BMI<16) photo.setImageResource(R.drawable.bmi_1); status.setText("您的健康狀態(tài)處于:n 偏瘦"); status.setTextColor(Color.BLUE);else if (d_BMI>=16 && d_BMI<20) photo.setImageResource(R.drawable.bmi_2

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論