android: stretch image in imageview to fit screen


Question

I have an imageview that has its height and width set to fill_parent with a linearlayout that has the same values set. So I suppose this should set my images to fit the screen. But it only fits like 80% (margin top and bottom in landscape mode).

I've tried the following code without success:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

imgView.setMinimumWidth(width);
imgView.setMinimumHeight(height);

imgView.setMaxWidth(width);
imgView.setMaxHeight(height);

Any other ideas?

1
122
12/30/2015 1:20:38 PM

Accepted Answer

use imgview.setScaleType(ScaleType.FIT_XY);

304
1/12/2011 11:46:49 AM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon