Java – Set ImageView width and height programmatically

androidandroid-emulatorandroid-widgetjava

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

Best Answer

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();