How to resize an imageview in Android via code?

2

I tried using LayoutParams but it did not work, I tried layoutParams.width = 80; and it did not work. Does anyone know how to do this? Thanks in advance.

In my case the image got too big I needed to slow down.

My code:

ImageView iv = new ImageView(this);
iv.setImageDrawable(getResources().getDrawable(R.drawable.verde));
    
asked by anonymous 06.01.2016 / 18:29

1 answer

1

You can try this code:

ImageView imageView = findViewById(R.id.dl_image);
LayoutParams params = (LayoutParams) imageView.getLayoutParams();
params.width = 120;
imageView.setLayoutParams(params);

Or you can still use two ImageView properties still in the XML that are

//Posiciona a imagem ao centro do elemento ImageView
android:scaleType="fitCenter"

//Redimensiona a imagem para que caiba toda no elemento ImageView
android:adjustViewBounds="true"

I particularly prefer to use the second option because it is more practical.

Att. Jeiferson

    
06.01.2016 / 23:47