在使用 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的视图打开以后,仔细检查了,却没有发现上图的提示:
最后我仔细检查了一遍,终于让我找到了:
解决问题!