android: stretch image in imageview to fit screen

Johan picture Johan · Jan 12, 2011 · Viewed 194.1k times · Source

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?

Answer

Pinki picture Pinki · Jan 12, 2011

to change pro-grammatically use :

imgview.setScaleType(ScaleType.FIT_XY);

OR

to change from xml use:

 android:scaleType="fitXY"