Skip to content
Advertisement

Remove extra space on button and remove rounded corner in Android Studio

I’m trying to make 4 buttons in a grid layout, but I don’t know how to remove the extra space on top and bottom on each button. I also don’t know how to remove the rounded corner. I tried to use cornerRadius but it does nothing.

Here’s the screenshot of the layout.As you can see, there’s a gap in the middle of top and bottom buttons.

enter image description here

Here’s the xml code:

<androidx.gridlayout.widget.GridLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="100dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="256dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <Button
            android:id="@+id/answerBtn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:backgroundTint="#9C27B0"
            android:onClick="chooseAnswer"
            android:tag="0"
            android:text="120"
            android:textSize="50dp"
            app:layout_column="0"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="0"
            app:layout_rowWeight="1" />

Advertisement

Answer

Try MaterialButton instead of Button

Add following attribute in MaterialButton

android:insetTop="0dp" // For default extra space from top
android:insetBottom="0dp" // For default extra space from bottom
android:insetLeft="0dp" // For default extra space from left
android:insetRight="0dp" // For default extra space from right
app:cornerRadius="0dp" // For corner radius

Full MaterialButton code:

<com.google.android.material.button.MaterialButton
            android:id="@+id/answerBtn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:backgroundTint="#9C27B0"
            android:onClick="chooseAnswer"
            android:tag="0"
            android:text="120"
            android:textSize="50dp"
            app:layout_column="0"
            app:layout_columnWeight="1"
            app:layout_gravity="fill"
            app:layout_row="0"
            app:layout_rowWeight="1"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            android:insetLeft="0dp"
            android:insetRight="0dp"
            app:cornerRadius="0dp"/>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement