This view is not constrained, it only has designtime positions, so it will jump to (0,0) unless you add constraints The

十年热恋 提交于 2019-12-12 08:53:46

问题


This view is not constrained, it only has designtime positions, so it will jump to (0,0) unless you add constraints.

The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as layout_editor_absoluteX.) These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.


回答1:


This may help someone. I am using Android Studio 3.1 and i faced same problem but i didn't find these options (Constraint Layout -> Infer Layout) as suggested in the above answer. Then after carefully checking i found "Infer Constraint" option above the layout window (refer to screenshot below in step 1)

Step 1: Click on "Infer Constraint". This may solve your problem, but if your widget still not visible (as in my case), then follow step 2.

Step 2: Click on "AppTheme" and select "NoTitleBar" theme as selected in the screenshot

This solved my problem.




回答2:


Right click on design layout in Android Studio, then select "Constrain Layout" and sub menu is open, then select "infer Layout" and compile your App.




回答3:


Android studio hint says:

This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints less... (Ctrl+F1) The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as layout_editor_absoluteX). These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor.

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




回答4:


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.




回答5:


In my project this error was caused by android:layout_width="fill_parent" and android:layout_height="fill_parent" expressions. fill_parent constant is obsolete. Changing to to match_parent solved the problem:

<ViewFlipper
    android:id="@+id/viewFlipper1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

</ViewFlipper>



回答6:


Add the following piece of code to your code:

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"


来源:https://stackoverflow.com/questions/45226854/this-view-is-not-constrained-it-only-has-designtime-positions-so-it-will-jump

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!