此视图不受垂直约束

This view is not constrained vertically

我刚刚更新 Android Studio 并尝试使用约束布局。 xml 属性中存在一些错误。

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.

我遵循以下步骤:

Right click on designing part > Constraint Layout > Infer Constraints

但我找不到 Constraint Layout

我也注意到推断约束并不总是有效。我所做的是,我:

  • 将我想要的视图拖到约束布局中,
  • 在屏幕上按照我希望的方式对齐它,
  • 手动创建其左约束与其父视图或另一个视图之间的连接,
  • 手动创建其顶部约束与其父视图或另一个视图之间的连接。

这种约束方式让我没必要infer constraints,因为我所有的观点都被约束了。如果出现任何错误,我 clear all constraints 然后为布局中的每个视图手动创建连接。

这是描述我的意思的图片:

我约束了left和top,这样就不需要推断了。

注意

  • 我正在使用 Android 3.0 和 1.0.2 的 ConstraintLayout 版本
  • 仅创建两个相互垂直的连接时效果很好,即 top/left、top/right、bottom/left、bottom/right.