Home >Java >javaTutorial >How to Programmatically Set the Dimensions of an ImageView?

How to Programmatically Set the Dimensions of an ImageView?

Barbara Streisand
Barbara StreisandOriginal
2024-11-15 01:51:021004browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn