Johan Andersson
Johan Andersson

Reputation: 11

Eliminate spacing between Android Imageview elements

I am trying to make a simple grid of images attached next to each other but can't seem to get rid of the ~5px spacing that automatically occurs between each element.

Any help would be greatly appreciated! Johan

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:layout_marginLeft="0px"
        android:layout_marginRight="0px"
        android:orientation="vertical"
         >
<ImageView   
  android:id="@+id/o1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginLeft="0px"
  android:layout_marginRight="0px"
  android:src="@drawable/p1
<ImageView   
  android:id="@+id/o2"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/o1"
  android:layout_marginLeft="0px"
  android:layout_marginRight="0px"
  android:src="@drawable/p2"/>
<ImageView   
  android:id="@+id/o3"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/o2"
  android:layout_marginLeft="0px"
  android:layout_marginRight="0px"
  android:src="@drawable/p3"/>
</RelativeLayout>

Upvotes: 1

Views: 1411

Answers (4)

Post Impatica
Post Impatica

Reputation: 16383

I found that when using the Android Studio built in import of Drawable resources, it was adding a border around my images, I assume to make them square. Also, in my case my images wheren't large enough. My understanding is Android will automatically scale down but not up.

Upvotes: 1

amsurana
amsurana

Reputation: 234

Add android:scaleType="fitXY" to your Image View to remove the blank spacing.

Upvotes: 0

Du3
Du3

Reputation: 1422

Add android:layout_toRightOf="@+id/01" to the second image. Do the same for the 3rd image. It's a relative layout, so you can do this.

Upvotes: 0

Femi
Femi

Reputation: 64700

Try adding android:padding="0px" to each element.

Upvotes: 0

Related Questions