为什么要使用约束布局,因为我们已经有了相对布局? [英] Why go for Constraints layout as we already have Relative Layout?

查看:490
本文介绍了为什么要使用约束布局,因为我们已经有了相对布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么将android空活动的默认布局文件中的RelativeLayout替换为ConstraintLayout.我需要知道为什么我们应该使用ConstraintLayout,它还能为我们带来什么好处.

Why RelativeLayout replaced to ConstraintLayout in the default layout file of an android empty activity. I need to know why we should use ConstraintLayout, what other benefits it provides to us.

推荐答案

-"ConstraintLayout的主要目的是修复RelativeLayout的问题,而且它做得很好.您可以做很多使用RelativeLayout不可能实现的事情.而且您可以前所未有地简化布局.此外,它还解决了RelativeLayout长期存在的性能问题.在度量/布局阶段进行了双重征税,因此我们可以获得更好的性能,在一个不错的软件包中提供了更多的多功能性和更简单的布局."

As provided by Xaver Kapeller - "The main purpose of the ConstraintLayout is to fix problems with the RelativeLayout, and it does it so well. You can do so many things that were impossible with a RelativeLayout. And you can simplify your layout like you never could before. Additionally, it fixes a long-standing performance issue of the RelativeLayout. The double taxation during the measure/layout phase. So we get better performance, more versatility and much simpler layouts in one nice package."

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

An additional benefit of using it is that it allows you to create your layouts using a drag and drop style editor visually in a way RelativeLayout couldn't similar to Interface Builder in Xcode.

约束布局:此新布局是应用程序的灵活布局管理器,可让您创建动态用户界面而无需嵌套多个布局.它作为与Android Studio紧密结合并向下兼容API Level 9的支持库进行分发.

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.

乍一看,约束布局类似于RelativeLayout. 但是,约束布局旨在用于Studio和 它可以有效地表达您的应用程序设计,从而减少您的依赖 诸如LinearLayout,FrameLayout,TableLayout或GridLayout之类的布局. 最后,使用内置的自动约束推理引擎.你 可以根据自己的喜好自由设计UI,并让Android Studio完成 努力工作.

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.

这篇关于为什么要使用约束布局,因为我们已经有了相对布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆