3 Answers3

1

It means exactly what it says, the view has no constraints set. The constraints are what set its position on the screen and relative position to other views. The way to fix the error is to add constraints, either with the GUI or in the XML file directly.

For example, to make it centered at the top of the screen you could set the following attributes in the XML file (click the "Text" tab below the image preview to edit the XML)

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

For more details about setting up a ConstraintLayout, including how to set constraints in the GUI rather than XML, check the user guide here. Whenever you drag a new component into your layout you will see this error until you've set constraints for it.

Tyler V
  • 9,694
  • 3
  • 26
  • 52
1

A view must have at least one horizontal and vertical constraint or else it would be scattered when run on a real device. The warning is for you to take note of that.

See sample of a well constraint view.

<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
joseph sarz
  • 191
  • 2
  • 7
0

Since when you create the view (Button, TextView etc) it has only a design-time view, you should set specific positions on the screen which you intend to locate the view exactly when the application is run. That is what mean by setting constraints. If the view should have at least one constraint. Otherwise it automatically goes in to the (0,0) location (top-left corner) when your run your application.

Setting Constraints

1.GUI (Design) Go to Design of your activity xml and drag from the anchors of the view and set the place or Go to Attributes -> Layout -> Constraint Widget and set values for the constraints.

enter image description here

2.Text

Following is the xml code of constraints corresponds to the above image.

 <Button>
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.117"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.499"></Button>

Hope this is somehow helpful. Happy coding!