AndroidStudioBMI计算器设计(三种计算标准)⼀:设计要求
BMI指数标准
⼆:设计框架
①布局界⾯:整体为线性布局、垂直分布分别有:标题、输⼊框、单选组、按钮、结论。
②java代码:
三:代码实现
布局界⾯:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="schemas.android/apk/res/android"
xmlns:tools="schemas.android/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_gravity="center"
android:text="BMI计算器"
android:textSize="35dp" />
<EditText
android:id="@+id/editheight"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请输⼊您的⾝⾼(以⽶为单位,例如1.75)" android:inputType="none|numberDecimal" />
<EditText
android:id="@+id/editweight"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请输⼊您的体重(以kg为单位,例如65)" android:inputType="number" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/who"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="WHO标准" />
<RadioButton
android:id="@+id/asian"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="亚洲标准(除中国外)" />
<RadioButton
android:id="@+id/China"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="中国标准" />
</RadioGroup>
<Button
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="计算"
android:textSize="30dp" />
<TextView
android: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;
@Override
protected void onCreate(Bundle 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() {
@Override
public void onClick(View v) {
double height = Double.Text().toString()); double weight = Double.Text().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()) {
android radiogroupif (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("您的体重过低,多吃点哦!");
}
}
}
});
}
}
四:模拟结果
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论