android – What is the reason for the error "This view is not constrained…" in ConstraintLayout?

Question:

Qual é a razão deste erro?

This view is not constrained, it only has designtime positions, so it will jump to (0,0) unless you add constraints

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.pedrogouveia.myapplication.MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoSizeStepGranularity="?android:attr/dialogPreferredPadding"
        android:text="SIGN UP"
        android:textColor="#54C571"
        android:textSize="25dp"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <EditText
        android:id="@+id/Primeiro Nome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Primeiro Nome"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="97dp" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Apelido"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="178dp" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textEmailAddress"
        android:text="e-mail"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="261dp" />

    <EditText
        android:id="@+id/editText4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword"
        android:text="password"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="347dp" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="266dp"
        tools:layout_editor_absoluteY="411dp" />
</android.support.constraint.ConstraintLayout>

Answer:

This view is not constrained, it only has designtime positions, so it will jump to (0,0) unless you add constraints.

This warning indicates that views do not declare enough constraints to be able to be placed.

That is, views do not indicate how they should be positioned relative to each other or relative to their "parent" layout . They will be positioned at coordinates (0,0).

In a ConstraintLayout each view must declare at least one horizontal and one vertical constraint. Each constraint represents a link or alignment to another view , "parent" layout , or an orientation.
Each constraint defines the position of the view along the vertical or horizontal axis.

Android Studio's layout editor, to show the layout consistently, automatically adds constraint attributes with absolute values ​​using namespace tools .
However they are not used at runtime.

These attributes are:

tools:layout_editor_absoluteX="valor"
tools:layout_editor_absoluteY="valor"

You have to add restrictions so that views can be positioned without the editor needing to add those attributes.

For more information on using the ConstraintLayout see:

Scroll to Top