android: stretch image in imageview to fit screen

给你一囗甜甜゛ 提交于 2019-11-27 10:20:45

use imgview.setScaleType(ScaleType.FIT_XY);

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.

Lalit kumar

use this:

ImageView.setAdjustViewBounds(true);
Ozear

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.

just change your ImageView height and width to wrap_content and use

exampleImage.setScaleType(ImageView.ScaleType.FIT_XY);

in your code.

Trying using :

imageview.setFitToScreen(true);
imageview.setScaleType(ScaleType.FIT_CENTER);

This will fit your imageview to the screen with the correct ratio.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!