Set ImageView width and height programmatically?

praveenb picture praveenb · Jun 29, 2010 · Viewed 532.2k times · Source

How can I set an ImageView's width and height programmatically?

Answer

Hakem Zaied picture Hakem Zaied · Mar 10, 2011

It may be too late but for the sake of others who have the same problem, to set the height of the ImageView:

imageView.getLayoutParams().height = 20;

Important. If you're setting the height after the layout has already been 'laid out', make sure you also call:

imageView.requestLayout();