RelativeLayout比LinearLayout贵吗? [英] Is a RelativeLayout more expensive than a LinearLayout?

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

问题描述

即使我只想显示非常简单的内容,由于它的灵活性,我每次都需要View容器时总是使用RelativeLayout.

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?

谢谢!

推荐答案

在Google 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天全站免登陆