Android Studio BMI计算器设计(三种计算标准)
一:设计要求
BMI指数标准
二:设计框架
①布局界面:整体为线性布局、垂直分布分别有:标题、输入框、单选组、按钮、结论。
②java代码:
三:代码实现
布局界面:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="BMI计算器"android:textSize="35dp" /><EditTextandroid:id="@+id/editheight"android:layout_width="fill_parent"android:layout_height="wrap_content"android:hint="请输入您的身高(以米为单位,例如1.75)"android:inputType="none|numberDecimal" /><EditTextandroid:id="@+id/editweight"android:layout_width="fill_parent"android:layout_height="wrap_content"android:hint="请输入您的体重(以kg为单位,例如65)"android:inputType="number" /><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:id="@+id/who"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="WHO标准" /><RadioButtonandroid:id="@+id/asian"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="亚洲标准(除中国外)" /><RadioButtonandroid:id="@+id/China"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="中国标准" /></RadioGroup><Buttonandroid:id="@+id/Button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="计算"android:textSize="30dp" /><TextViewandroid:id="@+id/TextView"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_gravity="center"android:gravity="center"android:text="结论"android:textSize="30dp" /></LinearLayout>
java代码:
public class MainActivity extends AppCompatActivity {private EditText edheight;private EditText edweight;private Button btn;private TextView conclusion;private RadioButton who;private RadioButton asian;private RadioButton China;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);edheight = (EditText) findViewById(R.id.editheight);edweight = (EditText) findViewById(R.id.editweight);btn = (Button) findViewById(R.id.Button);conclusion = (TextView) findViewById(R.id.TextView);who = (RadioButton) findViewById(R.id.who);asian = (RadioButton) findViewById(R.id.asian);China = (RadioButton) findViewById(R.id.China);btn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {double height = Double.valueOf(edheight.getText().toString());double weight = Double.valueOf(edweight.getText().toString());double bmi = weight / (height * height);if (who.isChecked()) {if (bmi >= 30) {conclusion.setText("您有点肥胖哦!");} else if (bmi >= 25) {conclusion.setText("您超重啦!");} else if (bmi >= 18.5 && bmi <= 24.9) {conclusion.setText("您的体重正常,继续保持哦!");} else if (bmi < 18.5) {conclusion.setText("您的体重过低,多吃点哦!");}} else if (asian.isChecked()) {if (bmi >= 27) {conclusion.setText("您有点肥胖哦!");} else if (bmi >= 24) {conclusion.setText("您超重啦!");} else if (bmi >= 18.5 && bmi <= 23.9) {conclusion.setText("您的体重正常,继续保持哦!");} else if (bmi < 18.5) {conclusion.setText("您的体重过低,多吃点哦!");}} else if (China.isChecked()) {if (bmi >= 27) {conclusion.setText("您有点肥胖哦!");} else if (bmi >= 24) {conclusion.setText("您超重啦!");} else if (bmi >= 18.5 && bmi <= 23.9) {conclusion.setText("您的体重正常,继续保持哦!");} else if (bmi < 18.5) {conclusion.setText("您的体重过低,多吃点哦!");}}}});}
}
四:模拟结果
Android Studio BMI计算器设计(三种计算标准)相关推荐
- 查找android studio版本号,Android studio版本号查看的三种方法
Android studio版本号查看的三种方法 发布于 2016-04-10 22:50:17 | 688 次阅读 | 评论: 0 | 来源: 网友投递 Android Studio Android ...
- android+rom+bootloader+flash,Android ROM开发(4) bootloader 三种启动模式
Andrew Huang 转载请注明作者及网址 HTC手机中用的bootloader称为HBoot,不知道是不是HTC Bootloader 之意,从官网的源码看这个bootloader不象是u-bo ...
- android 矢量图形文件,Android Studio进行APP设计开发之矢量图及XML文件转换
Android Studio进行APP设计开发之矢量图及XML文件转换 当我们使用Android studio进行APP设计开发时,会用到矢量图,那么要将矢量图运用到安卓工程drawable中去,就需 ...
- 【健康生活,从BMI开始——Melendez的Android版本BMI计算器开源了】
健康生活,从BMI开始--Melendez的Android版本BMI计算器开源了 健康生活,从BMI开始--Melendez的Android版本BMI计算器开源了 BMI是什么? 我的开源版本 感情各 ...
- 计算机最高单价公式,CFA考试中计算器的三种最高频率的用法
原标题:CFA考试中计算器的三种最高频率的用法 CFA考试中使用计算机的频率还是比较多的,但是你知道使用CFA考试中使用计算机最高频率的使用方法你知道吗?下边有小跃给大家分享一下在CFA考试中计算器的 ...
- Android Studio进行APP设计开发之矢量图及XML文件转换
Android Studio进行APP设计开发之矢量图及XML文件转换 当我们使用Android studio进行APP设计开发时,会用到矢量图,那么要将矢量图运用到安卓工程drawable中去,就需 ...
- android rom 工作,Android ROM开发(4) bootloader 三种启动模式
Andrew Huang 转载请注明作者及网址 HTC手机中用的bootloader称为HBoot,不知道是不是HTC Bootloader 之意,从官网的源码看这个bootloader不象是u-bo ...
- Android Studio 插件开发详解三:翻译插件实战
转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/78113868 本文出自[赵彦军的博客] 系列目录 Android Gradle使用 ...
- Android获取当前位置的三种方式及其使用方法
1.GPS定位 2.基站定位 此类位置的获取有赖于手机无线通讯信号,当手机处在信号覆盖范围内,手机可以获得该区域(即通讯术语中的"小区")的识别号.因为这些识别号是惟一的,因此可以 ...
最新文章
- UVa-442-Matrix Chain Multiplication
- CCU案件例及点评:设计渐进演化的知识结构
- leetcode算法题--多米诺与托米诺平铺★
- 【Android游戏开发十八】解放手指,利用传感器开发游戏!
- 【Matlab】找到矩阵中每个连通域的最小值
- linux war版本管理,linux(centos8):用systemctl管理war包形式的jenkins(java 14 / jenkins 2.257)...
- JS中函数的prototype属性和对象的__proto__属性
- 377. 组合总和 Ⅳ golang 动态规划
- oracle序时账是什么,序时账和明细账区别是什么
- LoadRunner性能测试-思考时间
- jvm面试 -- 谈谈ClassLoader ,ClassLoader的双亲委派机制 , loadClass和forName的区别
- 西瓜书+实战+吴恩达机器学习(十一)监督学习之集成学习
- 一般纳米材料是指尺度为_水溶性单分散纳米材料的开发意义
- 转:Java多线程学习(总结很详细!!!)
- HashMap源码阅读笔记
- 郁闷的出纳员 (splay) 题解
- 信息安全竞赛解决方案
- 运维笔记之调用163邮箱发送邮件
- 锂离子电池热失控预警方法综述
- Python爬取国家统计局官网最新全国所有城市县镇数据