to change pro-grammatically use :
imgview.setScaleType(ScaleType.FIT_XY);
OR
to change from xml use:
android:scaleType="fitXY"
Give in the xml file of your layout android:scaleType="fitXY"
P.S : this applies to when the image is set with android:src="..."
rather than android:background="..."
as backgrounds are set by default to stretch and fit to the View.
use this:
ImageView.setAdjustViewBounds(true);
if you use android:scaleType="fitXY"
then you must specify
android:layout_width="75dp"
and android:layout_height="75dp"
if use wrap_content it will not stretch to what you need
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:id="@+id/listItemNoteImage"
android:src="@drawable/MyImage"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="12dp"
android:scaleType="fitXY"/>
The accepted answer is perfect, however if you want to do it from xml, you can use android:scaleType="fitXY"
I Have used this android:scaleType="fitXY"
code in Xml file.
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