开发者

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" 
     开发者_C百科           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>


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.


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜