Layout constraint start top don’t work button disappears

  android, java

I have this activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<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">

    <TableLayout
        android:id="@+id/table_top"
        android:layout_marginTop="60dp"

        android:layout_width="355dp"
        android:layout_height="107dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        tools:layout_editor_absoluteY="40dp">

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

            <TextView
                android:id="@+id/first_name_label"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="First name:" />

            <EditText

                android:id="@+id/first_name_field"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />
        </TableRow>

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

            <TextView
                android:id="@+id/last_name_label"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Last name:" />

            <EditText
                android:id="@+id/last_name_field"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />
        </TableRow>

    </TableLayout>

    <Button
        android:id="@+id/calculate_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CALCULATE"
        android:textColor="#303030"
        app:backgroundTint="#CCCCCC"

        android:layout_marginStart="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="40dp"

        app:layout_constraintStart_toEndOf="@+id/table_top"
        app:layout_constraintTop_toBottomOf="@+id/table_top"
        />


</androidx.constraintlayout.widget.ConstraintLayout>

It looks like this:

enter image description here

If I remove

 app:layout_constraintStart_toEndOf="@+id/table_top"     
 app:layout_constraintTop_toBottomOf="@+id/table_top"

from the button, it looks like this:

enter image description here

I need to position the button beneath the table. Why the constraints didn’t help? How do I fix it?

Source: Android Questions

LEAVE A COMMENT