How to remove excess space above and below imageView?

I have a very simple image in RelativeLayout and for some reason I get an extra spacing above and below that I cannot remove. How can I clean this?

Here's what it looks like:

Image from Eclipse preview

Here is the code:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:src="@drawable/slice11pp" /> </RelativeLayout> 
+56
android imageview
Feb 28 '13 at 18:21
source share
11 answers

Try this

android:adjustViewBounds="true"

+212
03 Mar. '14 at 10:34
source share

In your above imageView just add android:scaleType="fitXY"

+7
Mar 28 '13 at 8:38
source share

Your problem is probably that you do not have a set of scale types ... Add it to the XML for ImageView, "fitCenter" should be correct, but there are others, check: ScaleType .

 <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:src="@drawable/slice11pp" android:scaleType="fitCenter" /> 
+5
Mar 28 '13 at 7:55
source share

It should be enough to add a property:

 android:adjustViewBounds="true" 

eg:

  <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:src="@drawable/slice11pp" android:adjustViewBounds="true" /> 

+3
Jan 29 '16 at 0:35
source share

If the height of your image matches match_parent, even if you set android: adjustViewBounds = "true", the ImageView will add extra blank space at the top and bottom. so change the height of the ImageView to wrap_content and set android: adjustViewBounds = "true"

eg

 <ImageView android:id="@+id/img_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true"/> 
+2
Feb 14 '17 at 10:50
source share

android: scaleType = "centerCrop" by adding this

 <ImageView android:id="@+id/image" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/temp_image" android:adjustViewBounds="true" android:scaleType="centerCrop"/> 

works for me before and after the image Before and After Image

+1
Aug 20 '18 at 19:57
source share

just add ScaleType = "fitxy" to the image view

0
Jul 01 '15 at 12:52
source share

try it

 <ImageView (...) android:adjustViewBounds="true" /> 
0
Apr 6 '17 at 7:23
source share

this is the perfect solution

  <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" android:scaleType="fitXY" /> 

he will not leave a single extra dp in any direction. however, the image will be distorted if it is not a portrait image.

0
Mar 03 '18 at 10:25
source share

Use the drawable-nodpi folder if there are no special image requirements. Then android: adjustViewBounds = "true" acts by default.

If you use drawable-nodpi, you do not need to set android:adjustViewBounds = "true" .

I think this is the easiest method.

0
Apr 17 '19 at 22:19
source share

It looks like the image you are setting is larger than the screen size.

you can try 2 things:

  • change the directory of your image to a higher resolution directory, for example, try putting it in drawable-xhdpi.

  • try setting match_parent for layout_width in ImageView.

-one
Mar 03 '13 at 0:09
source share



All Articles