BMI体重指数计算器

最近在自学android,先练手做一个小项目BMI。顺便了解一下如何写博客,如何使用GitHub,第一次写博客,有不好的地方还请大神赐教。

BMI指数(身体质量指数,简称体质指数,又称体重指数,英文为Body Mass Index,简称BMI)是用体重公斤数除以身高米数平方得出的数字。

BMI指数计算

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

BMI值 身体状况
bmi<18.5 过轻
18.5<=bmi<24 健康体重
24<=bmi<28 超重
bmi>=28 肥胖

好了,了解了BMI之后开始正式写代码。
其实做这个项目大体就需要两步,第一步是编写界面,第二步是按钮的点击事件。

首先先建一个BMI的android项目。

 先来几张app截图
这里写图片描述
这里写图片描述

现在开始我们的项目之旅~

编写界面

首先先要写这个界面,我们可以采用线性布局 ,垂直分布,其中身高和体重那里又需要一个线性布局,要把三个控件水平排放,好,直接上代码。

<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="com.example.mjy_bmi.MainActivity" >

 <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_gravity="center_horizontal"
 android:layout_marginTop="20dp"
 android:text="@string/title"
 android:textColor="#ff00ff"
 android:textSize="30dp" />

 <LinearLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginTop="20dp" >

 <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginLeft="50dp"
 android:layout_gravity="center"
 android:layout_weight="1"
 
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值