Android: can't remove vertical gap between images in LinearLayout

Enrico Detoma picture Enrico Detoma · Aug 31, 2010 · Viewed 10.8k times · Source

I have a simple LinearLayout in Android with two images vertically:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.eataly.android" 
    android:orientation="vertical"
    android:background="@android:color/white"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/img_header1"
        />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/img_header2"
        />
</LinearLayout>

As you can see at the following link, I can't get rid of a a gap at the top and at the bottom of the images: http://img185.imageshack.us/img185/8484/senzanomev.png

I've tried everything imaginable on the LinearLayout and the ImageViews, i.e.:

android:padding="0px"
android:top="0px"
android:bottom="0px"
android:top="0px"
android:layout_margin="0px"

with no success. What can I do to remove these empty borders?

Answer

Enrico Detoma picture Enrico Detoma · Oct 10, 2010

I found the solution. I needed to add this attribute to the ImageView:

android:adjustViewBounds="true"