ConstraintLayout之Infer Constraints(推断约束)

Posted Vicent_9920

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ConstraintLayout之Infer Constraints(推断约束)相关的知识,希望对你有一定的参考价值。

在使用 ConstraintLayout 的时候,发现一个异常:

This view is not constrained vertically: at runtime it will jump to the left unless you add a vertical constraint 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.

我仔细检查了约束条件,都是没有问题的,但是显示我缺少约束条件,编译后会将所有的控件堆在左上角,我选择了无视异常,但是异常没有无视我,编译后的效果类似于FarmeLayout没有添加位置约束一样的效果,后来查找百度,发现了解决方案:

1.切换xml到design试图下
2.选中ConstraintLayout右键选择Constraint Layout中的Infer Constraints

但是我将androidStudio的视图打开以后,仔细检查了,却没有发现上图的提示:

最后我仔细检查了一遍,终于让我找到了:

解决问题!

参考:

http://blog.csdn.net/u010296640/article/details/72922165

以上是关于ConstraintLayout之Infer Constraints(推断约束)的主要内容,如果未能解决你的问题,请参考以下文章

Android基础之布局ConstraintLayout

一分钟学会 ConstraintLayout 之从属性角度理解布局

ConstraintLayout属性之Group,GuideLine

Android 新控件之ConstraintLayout(约束布局)

ConstraintLayout2.0一篇写不完之约束到底写在哪

Android :约束布局ConstraintLayout 之 Chains 链式约束