MCPcopy
hub / github.com/JackyAndroid/AndroidInterview-Q-A / 22.d5fe6804.js

File 22.d5fe6804.js

docs/assets/js/22.d5fe6804.js:None–None  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1(window.webpackJsonp=window.webpackJsonp||[]).push([[22],{294:function(e,a,t){"use strict";t.r(a);var i=t(14),o=Object(i.a)({},(function(){var e=this,a=e._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h4",{attrs:{id:"linearlayout和relativelayout性能对比-百度"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#linearlayout和relativelayout性能对比-百度"}},[e._v("#")]),e._v(" LinearLayout和RelativeLayout性能对比-百度")]),e._v(" "),a("ol",[a("li",[e._v("RelativeLayout会让子View调用2次onMeasure,LinearLayout 在有weight时,也会调用子View2次onMeasure")]),e._v(" "),a("li",[e._v("RelativeLayout的子View如果高度和RelativeLayout不同,则会引发效率问题,当子View很复杂时,这个问题会更加严重。如果可以,尽量使用padding代替margin。")]),e._v(" "),a("li",[e._v("在不影响层级深度的情况下,使用LinearLayout和FrameLayout而不是RelativeLayout。")])]),e._v(" "),a("p",[e._v("最后再思考一下文章开头那个矛盾的问题,为什么Google给开发者默认新建了个RelativeLayout,而自己却在DecorView中用了个LinearLayout。因为DecorView的层级深度是已知而且固定的,上面一个标题栏,下面一个内容栏。采用RelativeLayout并不会降低层级深度,所以此时在根节点上用LinearLayout是效率最高的。而之所以给开发者默认新建了个RelativeLayout是希望开发者能采用尽量少的View层级来表达布局以实现性能最优,因为复杂的View嵌套对性能的影响会更大一些。")])])}),[],!1,null,null,null);a.default=o.exports}}]);

Callers

nothing calls this directly

Calls 2

tFunction · 0.85
aFunction · 0.85

Tested by

no test coverage detected