android - 为什么要选择约束布局,因为我们已经有了相对布局?

标签 android android-layout viewgroup android-constraintlayout

为什么android空activity的默认布局文件中的RelativeLayout替换为ConstraintLayout。我需要知道为什么我们应该使用 ConstraintLayout,它为我们提供了哪些其他好处。

最佳答案

由 Xaver Kapeller 提供 - “ConstraintLayout 的主要目的是解决 RelativeLayout 的问题,它做得很好。你可以做很多使用 RelativeLayout 不可能完成的事情。你可以简化你的布局就像你以前做不到的那样。此外,它修复了 RelativeLayout 长期存在的性能问题。在测量/布局阶段的双重征税。因此,我们在一个漂亮的包中获得了更好的性能、更多的多功能性和更简单的布局。”

使用它的另一个好处是,它允许您使用拖放样式编辑器以视觉方式创建布局,RelativeLayout 无法类似于 Xcode 中的 Interface Builder。

Constraint Layout: This new layout is a flexible layout manager for your app that allows you to create dynamic user interfaces without nesting multiple layouts. It is distributed as a support library that is tightly coupled with Android Studio and backwards compatible to API Level 9.

At first glance, Constraint Layout is similar to RelativeLayout. However, the Constraint Layout was designed to be used in Studio and it can efficiently express your app design so that you rely on fewer layouts like LinearLayout, FrameLayout, TableLayout, or GridLayout. Lastly, with the built-in automatic constraints inference engine. You can freely design your UI to your liking and let Android Studio do the hard work.

关于android - 为什么要选择约束布局,因为我们已经有了相对布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37992627/

相关文章:

android - 键盘将 EditText 隐藏在 android 中的 ScrollView 中?

以图像为中心的 Android Camera Preview

android - 我应该使用 Cursor 还是 CursorLoader?

android.content.res.Resources$NotFoundException : File res/drawable-v21/launch_background. xml

android - CollapsingToolbarLayout 问题 : overlapping UI with ToolBar

java - 在此示例中,如何从 View 组中仅删除删除按钮

android - 屏蔽触摸手势 - android

android - 无法在 Android Studio 中点击 XML 预览

java - 适用于 Android 的随机数学问题生成器

android - 防止/捕获 "IllegalArgumentException: parameter must be a descendant of this view"错误