Android入门项目:关于BMI体质指数计算器

目标:开发一款BMI体质指数计算器。用户在主界面中输入身高和体重,单击“计算BMI值”按钮后,在界面二通过TextView显示相应的结论;界面二点击返回能够回到主界面。

体质指数与胖瘦程度表

胖瘦程度 体质指数
过轻 男性低于20,女性低于19
适中 男性20—25,女性19—24
超重 男性25—30,女性24—29
肥胖 男性20—25,女性19—24
严重肥胖 男性高于35,女性高于34

BMI是体质指数,一种公认的评定个人体质胖瘦程度的分级方法,具体的计算方法如下:
体质指数(BMI)=体重(kg)/身高(m)^2

实现代码如下:
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/img04"
    tools:context="com.example.jinjin.bimtest.MainActivity"
    android:weightSum="1">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="身高(cm)" />
    <EditText
        android:id="@+id/height"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="体重(kg)" />
    <EditText
        android:id="@+id/weight"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <RadioButton
            android:id="@+id/btnMan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男"
            android:checked="true"/>
        <RadioButton
            android:id="@+id/btnWoman"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女"/>
    </RadioGroup>
    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="100dp"
        android:background="#E6E6FA"
        android:text="计算BMI值" />
</LinearLayout>

activity_second.xml

<?xml version=<
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值