我已经在xml文件中定义了imageview大小。因此,当图像出现时,它将作为默认值。我根据某些情况显示不同的图像。所以,我需要改变图像的宽度和高度。
XML格式:

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:visibility="invisible"  />

爪哇语:
if (text.equalsIgnoreCase("y")) {
      image.setImageResource(R.drawable.y);

      }
    else if (text.equalsIgnoreCase("z")) {
    image.setImageResource(R.drawable.z); // Here i need to change the width & height of the image
               }

最佳答案

你可以这样做:

imgView.getLayoutParams().height = 300;
imgView.getLayoutParams().width= 300;
imgView.requestLayout();//changing width and height programmatically will require the view to be redrawn

10-07 19:44
查看更多