Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android set image view height according to width

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

like image 596
Chrys Avatar asked Dec 06 '14 17:12

Chrys


People also ask

How can I set image width and height in android?

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.

What is the use of adjustViewBounds in android?

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.

What is ImageView in Android?

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.


1 Answers

You can use android:adjustViewBounds="true" in XML or setAdjustViewBounds(true) in code on your ImageView

like image 81
Dalija Prasnikar Avatar answered Sep 27 '22 18:09

Dalija Prasnikar