This view is not limited vertically. At run time, it will jump to the left unless you add a vertical constraint

enter image description here The new layout editor in Android Studio 2.2 continues to show this error on views such as EditText and buttons. kind help. Also, any links that help onboarding with a new layout constraint would be appreciated.

the code:

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout android:id="@+id/activity_main" 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.set.email.MainActivity" tools:layout_editor_absoluteX="0dp" tools:layout_editor_absoluteY="81dp"> <TextView android:text="To:" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:layout_editor_absoluteX="7dp" tools:layout_editor_absoluteY="4dp" android:id="@+id/textTo"/> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:ems="10" tools:layout_editor_absoluteX="0dp" tools:layout_editor_absoluteY="24dp" android:id="@+id/editTo" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> <EditText android:layout_width="384dp" android:layout_height="42dp" android:inputType="textPersonName" android:ems="10" tools:layout_editor_absoluteX="0dp" tools:layout_editor_absoluteY="94dp" android:id="@+id/editSubject" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> <EditText android:layout_width="384dp" android:layout_height="273dp" android:inputType="textPersonName" android:ems="10" tools:layout_editor_absoluteX="0dp" tools:layout_editor_absoluteY="179dp" android:id="@+id/editMessage" app:layout_constraintLeft_toLeftOf="@+id/activity_main" tools:layout_constraintLeft_creator="50" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> <Button android:text="Send" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:layout_editor_absoluteX="140dp" tools:layout_editor_absoluteY="454dp" android:id="@+id/btnSend" app:layout_constraintLeft_toLeftOf="@+id/editMessage" tools:layout_constraintLeft_creator="0" app:layout_constraintRight_toRightOf="@+id/activity_main" android:layout_marginEnd="16dp" tools:layout_constraintRight_creator="0" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> </android.support.constraint.ConstraintLayout> 
+61
android-layout android-studio android-edittext
Jun 16 '16 at 12:43 on
source share
10 answers

Layout restriction is aimed at reducing the layout hierarchy and improving layout performance (technically, you do not need to make changes for different screen sizes, without overlapping, it works like a charm on a mobile phone, as well as a tab with the same limitations). Here's how to get rid of the above error when using the new layout editor.

enter image description here

Click on the small circle and drag it to the left until the circle turns green to add a left constraint (specify a number, say, x dp. Repeat with the other sides and leave the lower constraint empty if you have another underneath. enter image description here

Change According to the developers website. Instead of adding constraints for each view, when you place them in the layout, you can move each view to the desired position and then click "Infer Constraints" to automatically create constraints. more details here

+64
Jun 22 '16 at 7:09
source share

From Android Studio v3 and higher, Infer Constraint has been removed from the drop-down list.

Use the magic wand icon in the toolbar menu above the project preview; there is a button " Infer Constraints ". Click this button, it will automatically add some lines to the text box, and the red line will be deleted.

enter image description here

+28
May 13 '18 at 17:03
source share

Go to the "Design" section, right-click your widget, Layout Restriction β†’ Infer Constraints. You may notice that some code has been automatically added to your text.

+21
Mar 26 '17 at 14:28
source share

Just copy this code into all the components that you will drag and drop.

 app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" 

example:

 <TextView app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" android:text="To:" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:layout_editor_absoluteX="7dp" tools:layout_editor_absoluteY="4dp" android:id="@+id/textTo"/> 
+19
Jun 04 '17 at 17:48
source share
 Follow these steps: Right click on designing part > Constraint Layout > Infer Constraints 
+4
Jun 27 '17 at 6:13
source share

If the output of Constraints still gives you an error, just use this code:

 app:layout_constraintBottom_toBottomOf="parent" 
+2
Sep 17 '17 at 12:31 on
source share

You need to drag EditText from the edge of the layout, and not just to another widget. You can also add constraints by simply dragging the constraint point that surrounds the widget to the edge of the screen to add constraints as indicated.

The modified code will look something like this:

  app:layout_constraintLeft_toLeftOf="@+id/router_text" app:layout_constraintTop_toTopOf="@+id/activity_main" android:layout_marginTop="320dp" app:layout_constraintBottom_toBottomOf="@+id/activity_main" android:layout_marginBottom="16dp" app:layout_constraintVertical_bias="0.29" 
+1
Jun 22 '16 at 7:14
source share

Go to the XML layout. The text where the widget (button or other view) indicates an error, focus the cursor and press alt + enter and select the missing constraint attributes.

+1
Nov 06 '17 at 10:52
source share

for example i have it

 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 

use a RelativeLayout layout like this

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
+1
May 15 '19 at 16:26
source share

Just switch to the constructor view and find the appropriate widget. Take one of the points on the border of the widget and attach it to the corresponding edge of the screen (or to a point on some other widget).

For example, if the widget is a toolbar, just grab the topmost point and attach it to the topmost edge of the phone screen, as shown.

Design view

0
Jun 25 '19 at 19:05
source share



All Articles