Why do I get white space on top and on the bottom of my ImageView in my RelativeLayout?

I had the exact problem. After struggling for quite some time, I solved it by following this

and add the following to my program

 android:adjustViewBounds="true"

It works perfectly


This is occuring as the image is scaled down to fit the area available without losing the image's aspect ratio. You are getting white space because the image first occupied the available width and according to the aspect ratio of the original image the height of the was brought down.

To get a clearer understanding, I suggest you to do the following :

  • Set the background color of the relative layout to some color

Now you can understand the space between the imageView and the relativelayout.

Once you have checked that on your device, Do the following change and try again

  • Set the attribute scaleType = "fitXY" in your imageView.

This will make the image to scale and occupy the complete area available to the imageView. (The aspect ratio of the original image will be lost in this case). Now you will come to know the amount of area the imageView occupied.

I suppose once you do this you can conclude that :

  1. In the first run if you had set the background of relativeLayout as black, it won't be visible since the imageView occupies the entire area without leaving any gap.

  2. In the second run the image will cover the entire height and width, although the aspect ratio was lost. Hence this ascertains that imageView does cover the width and height and no space is left, its the image's aspect ratio ie the problem

In case you arrive at a different result altogether please do inform, we can work it out

EDIT :

Please do remove the paddings you have given for imageView too