【发布时间】:2014-04-04 02:05:28
【问题描述】:
我有这个 imageView,我想一开始是不可见的...... 然后当我单击一个按钮(calculateButton)时,imageView 将是可见的。
这是我的 ImageView:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/resultLabel"
android:layout_below="@+id/resultLabel"
android:src="@drawable/image" />
这是我的calculateButton代码:
public void calculateClickHandler(View view) {
if (view.getId() == R.id.calculateButton) {
EditText weightText = (EditText) findViewById(R.id.weightText);
EditText heightText = (EditText)findViewById(R.id.heightText);
TextView resultText = (TextView)findViewById(R.id.resultLabel);
int weight = (int) Float.parseFloat(weightText.getText().toString());
int height = (int) Float.parseFloat(heightText.getText().toString());
int bmiValue = calculateBMI(weight, height);
String bmiInterpretation = interpretBMI(bmiValue);
resultText.setText("Your BMI is:" + " " + bmiValue + " " + bmiInterpretation); }
}
private int calculateBMI (int weight, int height) {
return (int) weight * 703 / (height * height) ;
}
private String interpretBMI(int bmiValue) {
if (bmiValue <= 16.0 && bmiValue <= 18.5) {
return "Underweight";
} else if (bmiValue > 18.5 && bmiValue <= 25 ){
return "Normal (Healthy)";
} else if (bmiValue > 25 && bmiValue <= 30 ) {
return "Overweight";
} else {
return "Obese"; }
}
}
【问题讨论】:
-
然后使用
imageview.setVisibility(View.VISIBLE);和imageview.setVisibility(View.INVISIBLE); -
非常感谢您的帮助。
标签: android imageview visibility