How can I set ImageView's height to keep it's aspect ratio? In XML I set fill_parent as layout width and wrap_content as layout height, but I got this: Screenshot http://kepfeltoltes.hu/141206/Screenshot_2014-12-06-19-09-30_1__www.kepfeltoltes.hu_.png
If you want to just fit the image in image view you can use" wrap content" in height and width property with scale-type but if you want to set manually you have to use LayoutParams. Layoutparams is efficient for setting the layout height and width programmatically.
adjustViewBounds=trueThe image is scaled uniformly and maintains the aspect ratio, in this case because the image will be equal or less than the ImageView it gets centered in it. Also the height is maintained since we are using adjustViewBounds.
ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics. drawable.
You can use android:adjustViewBounds="true"
in XML or setAdjustViewBounds(true)
in code on your ImageView
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