Home >Java >javaTutorial >How to Programmatically Set the Dimensions of an ImageView?
Manipulating ImageView Dimensions Programmatically
Setting the width and height of an ImageView through code is a common requirement in app development. Here's how to achieve it:
Setting ImageView Height:
imageView.getLayoutParams().height = 20;
Important Note: If you adjust the height after the layout has been initialized, ensure you call imageView.requestLayout(); to reflect the changes.
Setting ImageView Width:
To set the ImageView's width, use the following code:
imageView.getLayoutParams().width = 20;
Similarly, if the width adjustment occurs after the layout initialization, call imageView.requestLayout(); for the changes to take effect.
The above is the detailed content of How to Programmatically Set the Dimensions of an ImageView?. For more information, please follow other related articles on the PHP Chinese website!