Home > Net >  Android - Removing space between TableLayout Rows
Android - Removing space between TableLayout Rows

Time:11-17

I want to remove between the Button "0" and the Button "1". My goal is it to have the same space between them as the Button "X". Table layout without a space

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@ id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:insetBottom="0dp"
            android:text="1" />

        <Button
            android:id="@ id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:insetBottom="0dp"
            android:text="X" />
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <Button
            android:id="@ id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:insetTop="0dp"
            android:text="Button" />

        <Space
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5" />
    </TableRow>
</TableLayout>

CodePudding user response:

This is how you can do it

<TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    <TableRow>

        <TableLayout
                android:layout_width="0sp"
                android:layout_height="match_parent"
                android:layout_weight="1">

            <TableRow
                    android:layout_width="0sp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:padding="0sp">

                <com.google.android.material.button.MaterialButton
                        android:layout_width="0sp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:text="0" />
            </TableRow>

            <TableRow
                    android:layout_width="0sp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:padding="0sp">

                <com.google.android.material.button.MaterialButton
                        android:layout_width="0sp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:text="1" />
            </TableRow>
        </TableLayout>
        
        <com.google.android.material.button.MaterialButton
                android:layout_width="0sp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="X" />

    </TableRow>
</TableLayout>
  • Related