Android Studio - 约束布局与相对布局哪个更好?

Android Studio - Constraint Layout Vs Relative Layout Which Is Better?

约束布局为什么会错位,约束布局比相对布局好吗(新手在此)推荐哪个

" but when I create an Activity in a Constraint Layout, the items get misplaced during runtime why is that so?"

发生这种情况是因为您不能为视图添加所有必需的约束。

例如:如果您的视图仅与另一个视图顶部对齐,则在渲染时,它可能会水平移动到任何位置,因为它的左侧或右侧未对齐。

我建议您查看官方文档和示例。您还可以在 ConstraintLayout 上搜索 YouTube 教程。

约束布局优于相对布局,因为它同时提供了相对布局和线性布局的特性。您可以为 coordinatorlayout 中的视图提供权重,而相关布局中不存在该权重,因此我们需要添加另一层 linearlayout