Setting width and height of an ImageView

0

Hello, I need to change the size of a ImageView through class.java and I'm not sure what the command is.

Follow my code

xml

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageViewVermelho"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

class.java

iv_vermelho = (ImageView) findViewById(R.id.imageViewVermelho);

I need to size the image here

ex: if it were to do in xml it would be like this

android:layout_width="104dp"
android:layout_height="104dp"
    
asked by anonymous 28.08.2015 / 20:31

1 answer

1

To change the parameters of a View (any one that inherits it), you can use the LayoutParams native class.

In your case, to change the size of your ImageView dynamically, try something like this:

ImageView iv_vermelho = (ImageView) findViewById(R.id.imageViewVermelho);

//Acessando o LayoutParams de sua View
iv_vermelho.getLayoutParams().width = algumValor;
iv_vermelho.getLayoutParams().height = outroValor;
    
28.08.2015 / 21:12