0

I want to have a square which contains four buttons with no gaps between them and perhaps a border around the four buttons, I have been experimenting with table layouts as I feel these are easier to control layouts. I have reverted back to my original layout for this question as my latest attempt was a mess. You can see just now I have two buttons per row, I feel there should be four but it goes all wonky when I put four in. Here is my layout:

<TableRow
    android:layout_gravity="center_horizontal"
    android:layout_weight="1" >

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_column="0"
        android:layout_weight="1"
        android:gravity="center_horizontal" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_column="0"
        android:layout_weight="1"
        android:gravity="center_horizontal" />
</TableRow>

<TableRow
    android:layout_margin="0dp"
    android:layout_weight="1" >

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_column="0"
        android:layout_weight="1"
        android:gravity="center_horizontal" />

    <Button
        android:id="@+id/button4"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_column="0"
        android:layout_weight="1"
        android:gravity="center_horizontal" />
</TableRow>

Can anyone explain to me how I can achieve what I want? I also tried nesting table rows which of course failed. The documentation only further confused me, any advice is appreciated!

timrwood
  • 10,611
  • 5
  • 35
  • 42
deucalion0
  • 2,422
  • 9
  • 55
  • 99

1 Answers1

2

Set margins between buttons and tableRows to negative value like this:

    <Button
        android:id="@+id/id1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/id1"
        android:layout_marginBottom="-7dp" />
azizbekian
  • 60,783
  • 13
  • 169
  • 249
  • Thank you that appears to be working, but can you tell me how to get borders around the buttons? Thanks!! :) – deucalion0 May 11 '13 at 07:56
  • 1
    Include all your buttons in a single view, and then set background for that view an [xml drawable](http://stackoverflow.com/a/8203840/1083957). – azizbekian May 11 '13 at 18:52