I've look at MANY questions on Stackoverflow and tried many workaround but it still didn't work.
What I wanna achieve :
Yet I am achieving this :
This is my current xml code:
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@+id/text"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/ic_action_search" />
However, make sure you're setting the image to the ImageView using android:src="..." rather than android:background="..." . src= makes it scale the image maintaining aspect ratio, but background= makes it scale and distort the image to make it fit exactly to the size of the ImageView.
FIT_XY. Scale the image using Matrix. ScaleToFit#FILL . From XML, use this syntax: android:scaleType="fitXY" .
src: src is an attribute used to set a source file or you can say image in your imageview to make your layout attractive.
The best way to achieve this is to scale the image (bitmap) using a Matrix.
An alternative is to use a library I previously created which does this for you:
https://github.com/laurencedawson/ZoomableImageView
This will automatically scale the image to fit the screen and also add pinch to zoom.
add
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@+id/text"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/ic_action_search" />
CenterInside, Resize Image According To view dimensions and its Resolutions. So if an Image Has size of 300*450 and we have set this image to an imageview of scale type centerinside, with dimensions 200*400, then it will make size of image to 200*300, According to the target dimensions, so scaling it down make 200 is minimum in width and height. I hope I am clear enough. In cases where you need to set dimensions of exact size use FItXY, as suggested by Adeel.
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