问题描述
我始终使用LinearLayout和RelativeLayouts,并且在阅读有关新"的 PercentRelativeLayout .我有几个问题:
I always use LinearLayout and RelativeLayouts, and i was reading about the "new" PercentRelativeLayout. I have a few questions:
-
我应该总是开始使用这种方法还是仅在线性布局嵌套权重的情况下使用?
Should i always start using this one or only in cases of nested weights with linearlayout?
这比其他人表现更好吗?
Is this more performant than the others?
任何有关PercentRelativeLayout的信息都将受到欢迎.
Any other information about PercentRelativeLayout it will be welcome.
谢谢!
推荐答案
查看,基本上是RelativeLayout的次要扩展.这意味着您需要与在RelativeLayout和LinearLayout中进行选择时相同的注意事项.
Looking at the source code, a PercentRelativeLayout is basically a minor extension of a RelativeLayout. This means you need to make the same considerations as when you choose between a RelativeLayout and LinearLayout.
- RelativeLayout需要进行2次测量->避免将其用作深度视图层次结构的根或嵌套多个RelativeLayouts(更多信息,请参见帖子)
- RelativeLayout needs 2 measure passes -> avoid using it as the root of a deep view hierarchy or nesting multiple RelativeLayouts (more info in this stackoverflow post)
- Layout weights in LinearLayout also require 2 measure passes -> try to replace these constructs as much as possible with one Relative/GridLayout (more info in this stackoverflow post)
最后值得注意的是:
- 除非有问题,否则不要进行优化
- 尝试使层次结构尽可能平坦
这篇关于PercentRelativeLayout更有表现力吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!