How can I set an ImageView
's width and height programmatically?
Show activity on this post. extension UIImage { func imageResize (sizeChange:CGSize)-> UIImage{ let hasAlpha = true let scale: CGFloat = 0.0 // Use scale factor of main screen UIGraphicsBeginImageContextWithOptions(sizeChange, ! hasAlpha, scale) self. draw(in: CGRect(origin: CGPoint.
This example demonstrates how to resize Image in an Android App using Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
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();
If your image view is dynamic, the answer containing getLayout will fail with null-exception.
In that case the correct way is:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100); iv.setLayoutParams(layoutParams);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With