I have the following rectangular image to be set in my application.
Now I am trying to expand the image with same ratio on both sides until it fits to the screen.But I cant get the expected image.
So far my code is :
<ImageView
android:id="@+id/imgid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/shayneward"
android:scaleType="fitXY"/>
It dont care that the image gets cut off, but it should expand on both sides with same ratio until it fits to the screen.
Change android:scaleType="fitXY"
to android:scaleType="centerCrop"
to get the behavior that you want.
The different scaling options are documented under ImageView.ScaleType.
Try using this:
android:scaleType="centerCrop"
From the Android documentation, center crop does the following:
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
See documentation for ImageView.ScaleType
here.
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