2016-06-14 83 views
47

我收到以下错误,我正在使用Android studio 2.2 Preview 3.我搜索了Google,但找不到任何资源。此视图不受限制

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" /> 

回答

3

你需要通过点击工具栏上的魔术棒按钮来手动给出一个值来约束自动使用新的布局编辑器缺少约束可以添加时设计预览的菜单。

115

快速解决此问题,使用这个非常有用的快捷方式在Android的工作室:

右键单击窗口小部件功能于问题>约束布局>推断约束:

enter image description here

此后,您可以按照此处所述调整约束:https://stackoverflow.com/a/37960888/5556250

更新

这不适用于Android Studio v3及更高版本。按照@purpleladydragons's comment

“约束布局”不在下拉菜单中。使用设计预览上方工具栏菜单中的魔术棒图标;有“Infer Constraints”按钮。

+2

非常感谢您的解决方案,我是一个绝对的初学者,我不知道什么是错的部件位置 –

+1

的最佳解决方案,虽然我希望Android Studio只会存储起跑位置,而不是运行时间位置。更好的问题是谷歌为什么只在运行期间存储位置是个好主意?这是让开发者点击推断位置的不必要的步骤。 – Antony

+0

非常感谢!非常有帮助 – Paul

6

右键单击,然后在其中得到了错误组件设计部分,按照下列步骤操作:

  • [为前。如果发生在纯文本错误]

[1]

纯文本约束布局“,由此推断约束:

终于错误已经

8

你可以试试这个: 1。确保你已经添加了:compile'c​​om.android.support:design:25.3.1'(也许你还应该加上编译 'com.android.support.constraint:约束的布局:1.0.2') 2. enter image description here

3.click的推断约束,希望它可以帮助你。

21

Solution

只需点击此,它都将迎刃而解