项目背景

        BMI指数(即身体质量指数,简称体质指数又称体重,英文为Body Mass Index,简称BMI),是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。主要用于统计用途,当我们需要比较及分析一个人的体重对于不同高度的人所带来的健康影响时,BMI值是一个中立而可靠的指标

BMI值原来的设计是一个用于公众健康研究的统计工具。当我们需要知道肥胖是否为某一疾病的致病原因时,我们可以把病人的身高及体重换算成BMI值,再找出其数值及病发率是否有线性关连。不过,随着科技进步,现时BMI值只是一个参考值。要真正量度病人是否肥胖,体脂肪率比BMI更准确、而腰围身高比又比体脂肪率好、但是最好的看法是看内脏脂肪(若内脏脂肪正常,就算腰围很大及体脂肪率很高,健康风险不高,日本相扑很多都是这种胖法)。因此,BMI的角色也慢慢改变,从医学上的用途,变为一般大众的纤体指标。BMI是Body Mass Index 的缩写,BMI中文是“体质指数”的意思,是以你的身高体重计算出来的。BMI是世界公认的一种评定肥胖程度的分级方法,世界卫生组织(WHO)也以BMI来对肥胖或超重进行定义。

       体质指数算法:

       体质指数(BMI)=体重(kg)÷身高^2(m)

EX:70kg÷(1.75×1.75)=22.8

 指标:

WHO标准

亚洲标准

中国标准

相关疾病发病危险性

偏瘦

<18.5

低(但其它疾病危险性增加)

正常

18.5-24.9

18.5-22.9

18.5-23.9

平均水平

超重

≥25

≥23

≥24

 

偏胖

25.0~29.9

23~24.9

24~27.9

增加

肥胖

30.0~34.9

25~29.9

≥28

中度增加

重度肥胖

35.0~39.9

≥30

——

严重增加

极重度肥胖

≥40.0

非常严重增加

 

 

 





       不适合人群:

并不是每个人都适用BMI的,如:

1.未满18岁;

2.是运动员;

3.正在做重量训练;

4.怀孕或哺乳中;

5.身体虚弱或久坐不动的老人。

如果认为BMI算出来的结果不能正确反映体重问题,请带着结果与医师讨论,并要求做体脂肪测试。

项目效果

静态效果图:
 动态效果图:
  

项目结构

 注意:此项目是在依赖appcompat_v7_9项目下创建的,需要导入appcompat_v7_9并依赖此项目。
<uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

界面开发

注册文件:AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.kedi.bmi"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="14"android:targetSdkVersion="19" /><applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><activityandroid:name="com.kedi.bmi.MainActivity"android:label="@string/app_name" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>
</span>

字符串资源文件:values/string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources><!-- 字符串资源文件 --><string name="app_name">BMI指数计算器</string><string name="hello_world">Hello world!</string><string name="action_settings">Settings</string><string name="title">BMI指数计算器</string><string name="height">您的身高</string><string name="cm">(厘米)cm</string><string name="weight">您的体重</string><string name="kg">(千克)kg</string><string name="cala">计算</string><string name="re_cala">重新计算</string><string name="weight_bmi">您的体重指数:</string><string name="weight_state">您的体重状况:</string><string name="tip1">身高不能为空</string><string name="tip2">输入格式不正确</string><string name="tip3">体重不能为空</string>
</resources>

尺寸资源文件:values/dimens.xml

<resources><!-- 尺寸资源文件 --><!-- Default screen margins, per the Android Design guidelines. --><dimen name="activity_horizontal_margin">16dp</dimen><dimen name="activity_vertical_margin">16dp</dimen><dimen name="text_22">22sp</dimen><dimen name="text_16">16sp</dimen><dimen name="text_18">18sp</dimen><dimen name="margin_40">40dp</dimen><dimen name="margin_16">16dp</dimen></resources>

颜色资源文件:values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android"><!-- 颜色资源文件 --><color name="white" >#ffffff</color></resources>

主界面文件:layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/container"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/main_bg"android:orientation="vertical" ><!-- 标题栏 --><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/title_bg" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:text="@string/title"android:textColor="@color/white"android:textSize="@dimen/text_22"android:textStyle="bold" /></RelativeLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="@dimen/margin_40"android:orientation="vertical" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="@dimen/margin_40"android:gravity="center_horizontal"android:orientation="horizontal" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/height"android:textColor="@color/white"android:textSize="@dimen/text_16" /><EditTextandroid:id="@+id/et_height"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center_horizontal"android:inputType="numberDecimal"android:singleLine="true"android:textColor="@color/white"android:textSize="@dimen/text_16" ></EditText><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/cm"android:textColor="@color/white"android:textSize="@dimen/text_16" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center_horizontal"android:orientation="horizontal" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/weight"android:textColor="@color/white"android:textSize="@dimen/text_16" /><EditTextandroid:id="@+id/et_weight"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center_horizontal"android:inputType="numberDecimal"android:singleLine="true"android:textColor="@color/white"android:textSize="@dimen/text_16" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/kg"android:textColor="@color/white"android:textSize="@dimen/text_16" /></LinearLayout><Buttonandroid:id="@+id/btn_cala"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="@dimen/margin_16"android:text="@string/cala"android:textColor="@color/white"android:textSize="@dimen/text_18" /><LinearLayoutandroid:id="@+id/ll_result"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="@dimen/margin_16"android:orientation="vertical" ><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical" ><TextViewandroid:id="@+id/tv_bmi"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/weight_bmi"android:textColor="@color/white"android:textSize="@dimen/text_16" /><TextViewandroid:id="@+id/tv_state"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/weight_state"android:textColor="@color/white"android:textSize="@dimen/text_16" /></LinearLayout><Buttonandroid:id="@+id/btn_re_cala"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="@dimen/margin_16"android:text="@string/re_cala"android:textColor="@color/white"android:textSize="@dimen/text_18" /></LinearLayout></LinearLayout></LinearLayout>

功能开发

 主界面管理类:src/
                             com.kedi.bmi.MainActivity.java
package com.kedi.bmi;import java.text.DecimalFormat;import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;/*** BMI指数计算器主界面管理类* * @author 科弟* */
@SuppressLint("ShowToast")
public class MainActivity extends Activity implements OnClickListener {private EditText mHeightInputEt;// 身高输入框private EditText mWeightInputEt;// 体重输入框private Button mCalaBtn;// 计算按钮private LinearLayout mResultLl;// 计算结果布局private TextView mWeightBmiTv;// 体重指数文本private TextView mWeightStateTv;// 体重状态文本private Button mReCalaBtn;// 重新计算按钮private double height;// 身高private double weight;// 体重private double bmi;// bmi指数值private String state;// 体重状态private String weightBmi;// 您的体重指数:private String weightState;// 您的体重状况:// 可取体重状态值数组private String[] states = { "偏瘦", "正常", "偏胖", "肥胖", "重度肥胖", "极重度肥胖" };@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 去掉系统标题栏requestWindowFeature(Window.FEATURE_NO_TITLE);// 关联布局文件setContentView(R.layout.activity_main);// 初始化布局或控件initView();// 注册控件点击事件setViewListener();weightBmi = getResources().getString(R.string.weight_bmi);// 您的体重指数:weightState = getResources().getString(R.string.weight_state);// 您的体重状况:}/*** 初始化布局或控件的方法*/private void initView() {mHeightInputEt = (EditText) this.findViewById(R.id.et_height);// 身高输入框mWeightInputEt = (EditText) this.findViewById(R.id.et_weight);// 体重输入框mCalaBtn = (Button) this.findViewById(R.id.btn_cala);// 计算按钮mResultLl = (LinearLayout) this.findViewById(R.id.ll_result);// 计算结果布局mWeightBmiTv = (TextView) this.findViewById(R.id.tv_bmi);// 体重指数文本mWeightStateTv = (TextView) this.findViewById(R.id.tv_state);// 体重状态文本mReCalaBtn = (Button) this.findViewById(R.id.btn_re_cala);// 重新计算按钮// 默认显示计算按钮(VISIBLE),隐藏结果布局(GONE)mCalaBtn.setVisibility(View.VISIBLE);mResultLl.setVisibility(View.GONE);}/*** 注册控件点击事件的方法*/private void setViewListener() {mCalaBtn.setOnClickListener(this);mReCalaBtn.setOnClickListener(this);}@Overridepublic void onClick(View v) {int id = v.getId();switch (id) {case R.id.btn_cala:// 计算逻辑// 获取身高输入框数据String heightStr = mHeightInputEt.getText().toString().trim();// 判断身高输入框数据是否为空if ("".equals(heightStr) || heightStr.length() == 0) {Toast.makeText(this, getResources().getString(R.string.tip1), 0).show();} else {try {// 将String类型转化成Double类型height = Double.valueOf(heightStr);String weightStr = mWeightInputEt.getText().toString().trim();if ("".equals(weightStr) || weightStr.length() == 0) {Toast.makeText(this,getResources().getString(R.string.tip3),Toast.LENGTH_SHORT).show();} else {try {weight = Double.valueOf(weightStr);// 计算bmi值calaBmi();// 隐藏计算按钮(GONE),显示结果布局(VISIBLE)setViewVisible(false);} catch (Exception e) {Toast.makeText(this,getResources().getString(R.string.tip2),Toast.LENGTH_SHORT).show();}}} catch (Exception e) {Toast.makeText(this,getResources().getString(R.string.tip2),Toast.LENGTH_SHORT).show();}}break;case R.id.btn_re_cala:// 重新计算逻辑setViewVisible(true);break;}}/*** 计算bmi值*/private void calaBmi() {// height/100.0 cm换算成mheight = height / 100.0;bmi = weight / (height * height);if (bmi < 18.5) {state = states[0];} else if (bmi >= 18.5 && bmi <= 24.9) {state = states[1];} else if (bmi >24.9 && bmi <= 29.9) {state = states[2];} else if (bmi >29.9 && bmi <= 34.9) {state = states[3];} else if (bmi >34.9 && bmi <= 39.9) {state = states[4];} else {state = states[5];}}/*** 控制计算按钮与结果布局的显示与隐藏* * @param visible*/private void setViewVisible(boolean visible) {if (visible) {mCalaBtn.setVisibility(View.VISIBLE);mResultLl.setVisibility(View.GONE);// 清空数据mWeightBmiTv.setText("");mWeightStateTv.setText("");mHeightInputEt.setText("");mWeightInputEt.setText("");height = 0.0;weight = 0.0;} else {//获得焦点mHeightInputEt.requestFocus();// 格式化数据的类DecimalFormat format = new DecimalFormat("0.0");mCalaBtn.setVisibility(View.GONE);mResultLl.setVisibility(View.VISIBLE);mWeightBmiTv.setText(weightBmi + format.format(bmi));mWeightStateTv.setText(weightState + state);}}
}

源码下载

源码下载地址:http://download.csdn.net/detail/kedi_study/8934139

【BMI指数计算器V1.0】项目实战相关推荐

  1. 【BMI指数计算器V3.0】项目实战

    [BMI指数计算器V3.0]项目实战震撼发布,欢迎前来交流~~~,如果是刚来的朋友可以先从 [BMI指数计算器V1.0]项目实战,[BMI指数计算器V2.0]项目实战开始,这样循序渐进更能感受到每一个 ...

  2. 【BMI指数计算器V2.0】项目实战

    [BMI指数计算器V2.0]是建立在[BMI指数计算器V1.0]的基础上进行功能的增加,以版本迭代的方式循序渐进的进行Android核心技术的练习. 更新列表: 1.BMI计算标准选择 2.体重状态表 ...

  3. 【BMI指数计算器V4.0】项目实战

    前言 [BMI指数计算器V4.0]与[BMI指数计算器V3.0]实现的效果是一样的,不同的是在[BMI指数计算器V3.0]的基础上加入了Service层(服务),BroadcastReceiver(广 ...

  4. 如何用C语言和Python编写一个BMI指数计算器

    写在前面   前些日子在学习C语言和Python的循环语句的时候,我心血来潮,想编写一个实用性较高的程序.想来想去,我决定编写一个BMI指数计算器.接下来,我将分享一下我编写这个程序的过程,希望给大家 ...

  5. net core体系-web应用程序-4asp.net core2.0 项目实战(1)-11项目日志解决方案

    本文目录 1. Net下日志记录 2. NLog的使用     2.1 添加nuget引用NLog.Web.AspNetCore     2.2 配置文件设置     2.3 依赖配置及调用     ...

  6. net core体系-web应用程序-4asp.net core2.0 项目实战(1)-10项目各种全局帮助类

    本文目录 1.  前沿 2.CacheHelper基于Microsoft.Extensions.Caching.Memory封装 3.XmlHelper快速操作xml文档 4.Serializatio ...

  7. 存款利率计算器V1.0

    3.存款利率计算器V1.0 设银行定期存款的年利率rate为2.25%,已知存款期为n年,存款本金为capital元,试编程计算并输出n年后的本利之和deposit.程序中所有浮点数的数据类型均为do ...

  8. 使用Python语言实现Bmi指数计算器

    使用Python3.7实现Bmi指数计算器 使用Python中界面编程来实现Bmi指数计算器 1使用tkinter实现bmi指数计算器 使用Python中界面编程来实现Bmi指数计算器 1使用tkin ...

  9. js制作bmi指数计算器代码

    js制作bmi指数计算器代码,js实现bmi指数计算代码教程如下: 1.输入体重 2.输入身高 计算结果:计算出体重指数 js实现代码: function setKeyup(obj) {if (!ob ...

最新文章

  1. @import注解使用
  2. spark shuffle再补充
  3. npi阶段是什么意思_《如何阅读一本书》:4个问题、4个阶段,助你实现高效、快速阅读...
  4. html5圆形头像滚动效果,基于jQuery实现响应式圆形图片轮播特效
  5. String StringBuffer StringBuilder的异同
  6. 【NOI OpenJudge】【1.1】编程基础之输入输出
  7. RGB图像转为灰度图像原理
  8. TCP发送接收数据2
  9. java回调函数机制
  10. chrome消除缓存的默认设置
  11. mysql多表查询去重复数据_SQL重复记录查询 查询多个字段、多表查询、删除重复记录的方法...
  12. html设置字号为五号,怎么将公式编辑器里面编辑的公式大小设置为5号宋体
  13. 极客学院ios开发工程师系列课程
  14. 十进制与R进制之间的转换
  15. 盘点三种卫星图分幅导出的方法
  16. vue 移动端顶部导航组件
  17. [python网络应用]用python帮你实现疫情自动填报(第一期,目前实现半自动,实现全自动会继续更新)(西北工业大学-翱翔门户疫情填报)
  18. 200瓦PFC方案200瓦pfc控制器方案,采用ucc28019a
  19. Mysql, where clause is ambiguous
  20. cmd打开jupyter不自动弹出浏览器的解决方法

热门文章

  1. PCL_第12章_分割【2】
  2. Keil C251条件编译宏的应用实例
  3. 利用XML技术获取域名的世界排名数字
  4. 网站服务器布设,服务器机房搭建 线缆布放原则
  5. ctf流量分析练习一
  6. Tic-Tac-Toe人机对弈程序(python实现)
  7. 过程网络优化(PRONTO)基准测试过程-PRONTO heterogeneous benchmark | 开源数据集 | 故障诊断
  8. Matlab重复测量的方差分析,两因素重复测量方差分析,史上最详细SPSS教程!
  9. 开机流程,模块管理与loader0.0
  10. PMP笔记 第9章 项目资源管理