小编raj*_*raj的帖子

如何动态更改图像大小

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

xml:

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="100dp"
        android:layout_height="100dp"        
        android:visibility="invisible"  />
Run Code Online (Sandbox Code Playgroud)

爪哇:

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
               }
Run Code Online (Sandbox Code Playgroud)

android android-image android-imageview

2
推荐指数
1
解决办法
2123
查看次数

标签 统计

android ×1

android-image ×1

android-imageview ×1