BMI指数Body Mass Index身体质量指数,简称体质指数又称体重指数,BMI值是根据你的身高、体重按照一定的公式得出数值,是衡量你身体健康的参数。
<?xml version="1.0" encoding="utf-8"?>
<!--添加布局属性-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/lm"
tools:context=".MainActivity">
<!-- 文本框组件-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="身高(cm):"
android:textSize="20dp"
android:textColor="#000"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入身高"
android:id="@ id/b1"
android:maxLines="1"
android:textSize="20dp"
android:textColor="#000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="体重(kg):"
android:textSize="20dp"
android:textColor="#000"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入体重"
android:id="@ id/b2"
android:maxLines="1"
android:textSize="20dp"
android:textColor="#000"/>
<Button
android:id="@ id/s"
android:layout_width="165dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/shape"
android:text="计算体质指数"
android:textSize="25dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="您的BMI值为:"
android:textColor="#000"
android:textSize="20dp" />
<TextView
android:id="@ id/BMI"
android:layout_width="274dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textColor="#000"
android:textSize="30dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="建议:"
android:textColor="#000"
android:textSize="20dp" />
<TextView
android:id="@ id/p"
android:layout_width="348dp"
android:layout_height="93dp"
android:layout_gravity="center"
android:textColor="#000"
android:textSize="30dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:layout_width="110dp"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:layout_marginTop="120dp"
android:id="@ id/g"
android:text="关于BMI"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:id="@ id/t"
android:layout_marginTop="120dp"
android:layout_marginLeft="322dp"
android:text="退出"
android:textSize="25dp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
package com.example.iii;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.service.voice.VoiceInteractionSession;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Button a,g,t;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a=(Button) findViewById(R.id.s);
a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText b1=(EditText) findViewById(R.id.b1);
EditText b2=(EditText) findViewById(R.id.b2);
TextView BMI=(TextView) findViewById(R.id.BMI);
TextView p=(TextView) findViewById(R.id.p);
Double m=Double.parseDouble(b1.getText().toString());
Double n=Double.parseDouble(b2.getText().toString());
Double b=n/(m*m)*10000;
if (b<18.5){
BMI.setText(b.toString());
p.setText("过轻,建议提高营养摄入!");
}else if (b<24){
BMI.setText(b.toString());
p.setText("适中,建议保持当前状态!");
}else if (b<27){
BMI.setText(b.toString());
p.setText("过重,建议注意饮食适量!");
}else if (b<32){
BMI.setText(b.toString());
p.setText("肥胖,建议多运动!");
}else if (b>=32){
BMI.setText(b.toString());
p.setText("非常肥胖,建议就医!");
}
}
});
t=(Button)findViewById(R.id.t);
t.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MainActivity.this.finish();
}
});
g=(Button)findViewById(R.id.g);
g.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
});
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgfaicf
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01