Search code examples
androidandroid-constraintlayoutandroid-button

Button doesn't fully stick to bottom of screen in constraint layout


I constrain a button to the bottom of the screen, but unfortunately there is a small gap between the bottom border of the screen and the bottom border of the buttom:

enter image description here

My XML:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/navigationTabs"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        app:layout_constraintTop_toTopOf="parent"
        app:tabMinWidth="100dp"
        app:tabRippleColor="@null"
        />

    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="BUTTON"
        android:layout_margin="0dp"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <LinearLayout
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/navigationTabs" />


</androidx.constraintlayout.widget.ConstraintLayout>

What causes this gap? And how can I get rid of it?


Solution

  • It's the shadow around the button of the default background. Specify your own background and the gap will disappear. For example:

    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#A4ABA4"
        android:text="BUTTON"
        android:layout_margin="0dp"
        app:layout_constraintBottom_toBottomOf="parent"/>