I have an Android Application, where I have an ImageView, I need to keep the size constant, there can be various images that I need to put into this ImageView, of different sizes.
I just need to ensure that all the Images must fit into the ImageView, the Image should increase in size if it is smaller and should decrease, in case it is bigger.
Thanks a lot for your time.
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.
android:adjustViewBounds—If set to true, the attribute adjusts the bounds of the ImageView control to maintain the aspect ratio of the image displayed through it. android:resizeMode—The resizeMode attribute is used to make a control resizable so we can resize it horizontally, vertically, or around both axes.
Fix ImageView's size with dp or fill_parent and set android:scaleType to fitXY.
In your case you need to
android:scaleType to fitXY Below is an example:
<ImageView android:id="@+id/photo" android:layout_width="200dp" android:layout_height="100dp" android:src="@drawable/iclauncher" android:scaleType="fitXY"/> For more information regarding ImageView scaleType please refer to the developer website.
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