Android Studio 3.1.3 Error: The view is not constrainted. How to solve this permanently?
Android Studio 3.1.3 Error: The view is not constrainted. How to solve this permanently?
Whenever I try to drag and drop "Button" or "TextView", it give the error message with a red exclamation mark. How to solve this permanently?
enter image description here
2 Answers
2
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.
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" />
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
See also: stackoverflow.com/questions/42594033/…
– CommonsWare
2 hours ago