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

How to Programmatically Set the Dimensions of an ImageView?

Barbara Streisand
Release: 2024-11-15 01:51:02
Original
1052 people have browsed it

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;
Copy after login

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;
Copy after login

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 of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template