与其他相比,约束布局昂贵吗? [英] Is Constraint Layout expensive compared to others?

查看:82
本文介绍了与其他相比,约束布局昂贵吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我意识到ConstraintLayout具有:

When I realize ConstraintLayout has:

  • 更好的布局拖放

  • better layout drag-drop

更好地命名"top-toBottomOf"来更好地查看相对设置

better view relative set-up with better naming "top-toBottomOf"

具有比率和百分比准则的更好的布局构造

better layout construction with ratios and percentage-guidelines

还有更多无法说明的地方,或者我只是不知道

and much more cant state here or I just didn't know

我一直想经常使用它,因为它是如此舒适.

that I was always wanted to using it constantly because it is so comfortable.  

就像标题一样,我很好奇 ConstraintLayout在经常使用时会带来很大的性能影响吗?

Just like the title, I curious about did ConstraintLayout will give big performance impact when using it constantly?

声明您的观点和证据将不胜感激.

Statement your opinion and evidence will be appreciated.

如果您的版本/语法好的话,欢迎进行编辑,并且不赞成投票,请在结论下方留下您的结论.感谢Dennis的语法校正.

推荐答案

约束布局是否比其他布局昂贵?

Are Constraint Layout expensive compared to others?

取决于取决于您的使用情况. ConstraintLayout类似于类固醇上的RelativeLayout.

It Depends upon your usage. A ConstraintLayout is like the RelativeLayouton Steroids.

如果您想要一个简单的2-3 ChildViews布局,那么使用ConstraintLayout不会那么有效.进入线性布局.

" ConstraintLayout 的主要目的是解决 RelativeLayout 的问题,而且效果很好. RelativeLayout .您可以前所未有地简化布局.此外,它还解决了RelativeLayout的长期性能问题.在 measure/layout阶段这样一来,我们就能在一个不错的程序包中获得更好的性能,更多的功能和更简单的布局."

"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 long-standing performance issues 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."

由于性能改进是创建此新布局的主要原因之一,因此我进行了一些性能测试,以检查是否满足此目标.

Since performance improvements are among the main reasons to create this new layout, I did some performance tests to check if this goal is met.

我比较了RecyclerView中使用的布局.没什么花哨的,只是一些嵌套的LinearLayout和RelativeLayout容器.我将此布局手动移到ConstraintLayout上,并进行了一些相当草率的性能测试.

I compared a layout used within a RecyclerView. Nothing too fancy, just some nested LinearLayout and RelativeLayout containers. I moved this layout manually over to ConstraintLayout and did some rather sloppy performance tests.

在使用新的ConstraintLayout时,在模拟器和Nexus 5上进行比较会导致整体性能下降.

Comparing those two on an emulator as well as on a Nexus 5 yielded overall a performance penalty when using the new ConstraintLayout.

最糟糕的是测量. onMeasure()方法花费的时间大约是我用于比较的LinearLayout方法的十倍.并且它花费了大部分时间,大约是onLayout()的60倍.因此,与所讨论的LinearLayout之一相比,ConstraintLayout的onLayout()方法的命中率几乎没有关系.最后,使用ConstraintLayout比使用LinearLayout,布局膨胀还花费了更长的时间.

Performing worst is the measurement. The onMeasure() method takes roughly ten times as long as the one of the LinearLayout I used for comparison. And it uses up the bulk of the time with taking about 60 times as long as onLayout(). Thus the 30 percent hit of the onLayout() method of ConstraintLayout compared to the one of the LinearLayout in question is nearly irrelevant. Finally, layout inflation also took longer with ConstraintLayout than with LinearLayout.

ConstraintLayout进行了大量的计算,以找出在何处以及如何显示其每个子项.在内部(至少)三个很长的类正在协同工作以获取结果:LinearSystemConstraintWidgetConstraintWidgetContainer.为了完全理解性能行为,我必须深入研究这些类的深度(为此,我更喜欢在Google发布其来源时使用注释的类).但是,只要粗略地看一下反编译的代码,看起来这些类就必须做很多事情.

The ConstraintLayout does lots of calculations to find out where and how to display each of its children. Internally (at least) three rather lengthy classes are working together to get the results: LinearSystem, ConstraintWidget, and ConstraintWidgetContainer. To fully understand the performance behavior I would have to dig into the depth of these classes (and for this, I prefer the commented classes when their sources are released by Google). But just by having a cursory look at the decompiled code it looks like those classes have to do a lot.

一些烦恼

但是,目前并非所有人都能正常工作.现在,这些事情最让我感到困扰:

Not all is working perfectly at the moment, though. Right now these things bother me the most:

  • 蓝图变更和设计预览之间存在明显的滞后 变化
  • 预览并不总是正确的
  • 蓝图视图不注意文本布局约束
  • 约束并不总是能按预期工作
  • 撤消工作非常不可靠
  • There’s a noticeable lag between blueprint changes and design preview changes
  • The preview is not always correct
  • The blueprint view doesn’t heed text layout constraints
  • Constraints do not always work as expected
  • Undo works very unreliably

编辑器以意外方式更新或更改内容

The editor updos stuff or changes stuff in unexpected ways

帖子支持ConstraintLayout.

This post supports ConstraintLayout.

个人而言,当我要对齐3个以上视图时,我仅使用ConstraintLayout.它很容易使用,但同时令人讨厌.

Personally, I only use ConstraintLayout, when I want to Align more than 3 views. It's easy to use but at the same time, annoying in the beginning.

tl:dr

这篇关于与其他相比,约束布局昂贵吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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