user10694817
user10694817

Reputation:

Resize ImageView programmatically

I'm working with an ImageView and I want to resize it programmatically passing (for example) from a full-screen ImageView to a 50x50. Is there a way to do that? Different from the one you suggested me to see because I don't need to fit the image in the ImageView but to resize the dimension of the ImageView.

Upvotes: 2

Views: 2158

Answers (3)

Tanveer singh Bhatia
Tanveer singh Bhatia

Reputation: 69

ConstraintLayout provides a mechanism for fixing the aspect ratio of a child view. Select the child view that we want to control, and then set the ratio value, we can manually put the ratio that we want to set. Using constraintLayout makes UI shrink or expand according to screen size without distorting the UI. This is the most important advantage of using ConstraintLayout in UI.

Upvotes: 0

Al-Amin
Al-Amin

Reputation: 1387

You can use LayoutParams to set height width programmatically -

ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
layoutParams.width = 30;
layoutParams.height = 30;
imageView.setLayoutParams(layoutParams);

Upvotes: 1

Mystogan
Mystogan

Reputation: 114

My suggestion use a relative layout and put image inside that has with weight and able to auto resize which depends on the weight. The best way to auto resize even your screen rotates.

I didn't remember which one layout has weight format

Upvotes: 1

Related Questions