1

As the title states, I simply want to have a layout with as little to no space between the columns/rows that are in a grid layout. Refer to the image below as the example. I simply want all the buttons to take up all the space of the cell they are in and the adjacent cells to go right up against each other. This will allow for a more tile look.

I have looked at this question: GridLayout (not GridView) how to stretch all children evenly - As well as this: GridLayout(not GridView) - Spaces between the cells

But it does not answer or solve my issue. Thank you so much for your help and advice.

Here is my XML code for the gridLayout.

GridLayout
    android:id="@+id/grid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#32ffffff"
    android:rowOrderPreserved="false"
    android:columnCount="3"
    android:padding="10dp"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true">

    <Button
        android:id="@+id/hello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_row="0"
        android:text="Hello"
        android:layout_columnWeight="1"
        android:layout_columnSpan="2"
        android:layout_gravity="fill"
        android:padding="5dp"/>

    <Button
        android:id="@+id/sorry"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_row="1"
        android:layout_gravity="fill"
        android:text="Sorry" />

    <Button
        android:id="@+id/thank"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_row="1"
        android:layout_gravity="fill"
        android:text="Thank You" />

    <Button
        android:id="@+id/myname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="My \nName \nIS"
        android:layout_column="2"
        android:layout_row="0"
        android:layout_rowSpan="2"
        android:layout_rowWeight="1" />

    <Button
        android:id="@+id/howto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How To Say ..?"
        android:layout_columnSpan="2"
        android:layout_column="0"
        android:layout_row="2"
        android:layout_columnWeight="1"
        android:layout_gravity="fill"/>

    <Button
        android:id="@+id/welcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_row="2"
        android:text="You're\nWelcome" />

    <Button
        android:id="@+id/yourname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your Name?"
        android:layout_column="0"
        android:layout_row="3"
        android:layout_gravity="fill"
        />

    <Button
        android:id="@+id/howareyou"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How are you?"
        android:layout_columnSpan="2"
        android:layout_column="1"
        android:layout_row="3"
        android:layout_columnWeight="1"
        android:layout_gravity="fill"/>

    <Button
        android:id="@+id/english"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Do you speak english?"
        android:layout_columnSpan="3"
        android:layout_column="0"
        android:layout_row="4"
        android:layout_columnWeight="1"
        android:layout_gravity="fill"/>

</GridLayout>

Android layout at the moment

Community
  • 1
  • 1
ZarifS
  • 467
  • 1
  • 11
  • 20

1 Answers1

2

The Button have a default padding.You can set a background to change it.

    <GridLayout
    android:id="@+id/grid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="#32ffffff"
    android:columnCount="3"
    android:padding="10dp"
    android:rowOrderPreserved="false">

    <Button
        android:id="@+id/hello"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnSpan="2"
        android:layout_columnWeight="1"
        android:layout_gravity="fill"
        android:layout_row="0"
        android:background="#ffffff"
        android:padding="5dp"
        android:text="Hello" />

    <Button
        android:id="@+id/sorry"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_gravity="fill"
        android:layout_row="1"
        android:background="#ffffff"
        android:text="Sorry" />

    <Button
        android:id="@+id/thank"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_gravity="fill"
        android:layout_row="1"
        android:background="#ffffff"
        android:text="Thank You" />

    <Button
        android:id="@+id/myname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_row="0"
        android:layout_rowSpan="2"
        android:layout_rowWeight="1"
        android:background="#ffffff"
        android:text="My \nName \nIS" />

    <Button
        android:id="@+id/howto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnSpan="2"
        android:layout_columnWeight="1"
        android:layout_gravity="fill"
        android:layout_row="2"
        android:background="#ffffff"
        android:text="How To Say ..?" />

    <Button
        android:id="@+id/welcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="2"
        android:layout_row="2"
        android:background="#ffffff"
        android:text="You're\nWelcome" />

    <Button
        android:id="@+id/yourname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_gravity="fill"
        android:layout_row="3"
        android:background="#ffffff"
        android:text="Your Name?" />

    <Button
        android:id="@+id/howareyou"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_columnSpan="2"
        android:layout_columnWeight="1"
        android:layout_gravity="fill"
        android:layout_row="3"
        android:background="#ffffff"
        android:text="How are you?" />

    <Button
        android:id="@+id/english"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_columnSpan="3"
        android:layout_columnWeight="1"
        android:layout_gravity="fill"
        android:layout_row="4"
        android:background="#ffffff"
        android:text="Do you speak english?" />

</GridLayout>
andy
  • 51
  • 3