<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="BMI计算器"
android:textSize="45sp"
android:gravity="center"
android:textColor="@color/colorPrimary"
/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="身高(M):"
android:textSize="25sp"
/>
<EditText
android:id="@+id/height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入您的身高"
/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="体重(KG):"
android:textSize="25sp"
/>
<EditText
android:id="@+id/weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入您的体重"
/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/btn"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="计算BMI"
android:textSize="25sp"
/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="您的BMI指数为:"
android:textSize="20sp"
/>
<EditText
android:id="@+id/bmi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="10dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bmi"
/>
LinearLayout>
LinearLayout>
```java
ackage com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bmi);
final EditText etHeight = findViewById(R.id.height);
final EditText etWeight = findViewById(R.id.weight);
final EditText etBmi = findViewById(R.id.bmi);
Button button = findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// String heightStr = etHeight.getText().toString();
// String weightStr = etWeight.getText().toString();
// if (!TextUtils.isEmpty(heightStr) && !TextUtils.isEmpty(weightStr)) {
double height = Double.parseDouble(etHeight.getText().toString());
System.out.println(height);
double weight = Double.parseDouble(etWeight.getText().toString());
System.out.println(weight);
double bmi = weight / (height * height);
System.out.println(bmi);
etBmi.setText(String.format("%2f",bmi));
// }
}
});
}
}

。。。
体重/(身高*身高) = 1.76/(70*70)
你说是多少?
你奥特曼,身高70m?