机器人:是一个RelativeLayout的比的LinearLayout更贵? [英] Android: Is a RelativeLayout more expensive than a LinearLayout?

查看:134
本文介绍了机器人:是一个RelativeLayout的比的LinearLayout更贵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用RelativeLayout的,每次我需要一个View容器,因为它的灵活性,即使我只是想展示的东西真的很简单。

I've always been using RelativeLayout everytime I needed a View container, because of it's flexibility, even if I just wanted to display something really simple.

它是确定这样做,或者我应该尝试使用的LinearLayout时,我可以,从性能/良好做法的立场?

Is it ok to do so, or should I try using a LinearLayout when I can, from a performance/good practices standpoint?

谢谢!

推荐答案

在一次谈话在谷歌I / O 2013(编写自定义视图为Android),罗曼盖伊澄清,导致​​每个人都开始使用RelativeLayouts一切的误解。一个RelativeLayout的总是做两措施通行证。整体而言,这是微不足道的,只要你的视图层次是简单的。但是,如果您的层次结构是复杂的,做了额外的传球可能是相当昂贵的。此外,如果你的巢RelativeLayouts,你会得到一个指数测量算法。

In a talk at Google I/O 2013 (Writing Custom Views for Android), Romain Guy clarified the misunderstanding that caused everyone to start using RelativeLayouts for everything. A RelativeLayout always has to do two measure passes. Overall it is negligible as long as your view hierarchy is simple. But if your hierarchy is complex, doing an extra measure pass could potentially be fairly costly. Also if you nest RelativeLayouts, you get an exponential measurement algorithm.

https://www.youtube.com/watch?v=NYtB6mlu7vA& T = 1m41s

https://www.youtube.com/watch?v=NYtB6mlu7vA& T = 38m04s

这篇关于机器人:是一个RelativeLayout的比的LinearLayout更贵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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