Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This view is not constrained

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 

enter image description here

<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" /> 
like image 296
Isuru Avatar asked Jun 14 '16 16:06

Isuru


People also ask

How do I fix this view is not constrained?

To resolve this error, you need to add constraints to the Button view that fulfills the minimum requirement of the ConstraintLayout view. You can do this in two ways: Using the Infer Constraints option from the Design window's toolbar. Using the Constrain option from the View 's context menu.

How do you fix this view is not constrained it only has Designtime positions so it will jump to 0 0 at runtime unless you add the constraints?

To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.

How do you constrain a view?

To create a baseline constraint, right-click the text view you want to constrain and then click Show Baseline. Then click on the text baseline and drag the line to another baseline.


2 Answers

To quickly resolve this, use this very helpful shortcut in Android Studio:

Right-click widget-in-question > Constraint Layout > Infer Constraints:

enter image description here

Thereafter, you can tweak the constraints as described here: https://stackoverflow.com/a/37960888/5556250

Update

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.

like image 118
Jay Souper Avatar answered Sep 18 '22 22:09

Jay Souper


Solution

Just click this and it will be solved

like image 31
Cem U Avatar answered Sep 18 '22 22:09

Cem U