What is the reason for the "This view is not constrained ..." error in ConstraintLayout?

2

What is the reason for this error?

  

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>
    
asked by anonymous 22.06.2017 / 00:05

1 answer

1
  

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 does not declare constraints ( constraints ) sufficient so that they can be positioned.

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

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

The Android Studio layouts editor to consistently show layout automatically adds constraint attributes to 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 must add constraints so that views can be positioned without the need for the editor to add those attributes.

For more information on using ConstraintLayout see:

22.06.2017 / 16:49