Reputation: 1263
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" />
Upvotes: 9
Views: 9494
Reputation: 11285
You want to do it inside the XML file right?
<ImageView
android:layout_width="size of image (in density pixels)"
android:layout_height="size of image (in density pixels)" />
so for example:
<ImageView
android:layout_width="60dp"
android:layout_height="60dp" />
Upvotes: 0
Reputation: 385
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" />
Upvotes: 3
Reputation: 12249
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.
Upvotes: 3
Reputation: 29199
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.
Upvotes: 1