I get the following error and I am using Android studio 2.2 Preview 3. I searched Google but couldn’t find any resources.
Error: This view is not constrained, it only has design time positions, so it will jump to (0,0) unless you add constraints
<TextView android:layout_width="384dp" android:layout_height="207dp" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/calc_default_display" android:id="@+id/textView" android:background="#ffffff" android:layout_margin="0dp" android:gravity="bottom|end" android:textSize="70sp" android:nestedScrollingEnabled="false" android:maxLines="2" android:maxLength="17" tools:layout_editor_absoluteX="0dp" tools:layout_editor_absoluteY="0dp" />
To quickly resolve this, use this very helpful shortcut in Android Studio:
Right-click widget-in-question > Constraint Layout > Infer Constraints:
Thereafter, you can tweak the constraints as described here: https://stackoverflow.com/a/37960888/5556250
This is not correct for the Android Studio v3 and up. As per @purpleladydragons’s comment:
“Constraint Layout” is not in the dropdown menu. Use the magic wand icon in the toolbar menu above the design preview; there is the “Infer Constraints” button.
You need to give a value to the constraints manually when using the new layout editor or the missing constraints can be added automatically by clicking the magic wand button in the toolbar menu of the design preview.
3.click the Infer Constraints, hope it can help you.
Alright so I know this answer is old, but I found out how to do this for version 3.1.4. So for me this error occurs whenever I put in a new item into the hierarchy, so I knew I needed a solution. After tinkering around for a little bit I found how to do it by following these steps:
- Right click the object and go to Center.
- Then select Horizontally.
- Repeat those steps, except click Vertically instead of Horizontally.
Provided that that method still works, after step two you should see squiggly lines going horizontally across where the item is, and after step three, both horizontally and vertically. After step three, the error will go away!
Right Click in then designing part on that component in which you got error and follow these steps:
- [for ex. if error occur in Plain Text]
Plain Text Constraint Layout > Infer Constraints:
finally error has gone
Right-click on the widget and choose “center” -> “horizontally”. Then choose “center”->”vertically”.
From Android Studio v3 and up, Infer Constraint was removed from the dropdown.
Use the magic wand icon in the toolbar menu above the design preview; there is the “Infer Constraints” button. Click on this button, this will automatically add some lines in the text field and the red line will be removed.
You just have to right-click on the widget and choose “center” -> “horizontally” and do it again then choose ->”vertically”
This worked for me…
you can go to the
XML file then focus your mouse cursor into your button, text view or whatever you choose for your layout, then press
Alt + Enter to fix it, after that the error will be gone.it works for me.
After clicking on the magic wand icon to infer constraints:
1) In Projects window, go to Gradle Scripts > build.gradle (Module:app)
2) Scroll down to dependencies
3) Look for implementation ‘com.android.support:appcompat-v7:28.0.0-beta03’
4) Change this line to implementation ‘com.android.support:appcompat-v7:28.0.0-alpha1’
5) A banner should pop up at the top of the window, click Sync Now in the right corner.
This works for Android Studio v3.1
click for image of edit to build.gradle file