Why are nested weights bad for performance? Alternatives?

后端 未结 6 1598
深忆病人
深忆病人 2020-11-22 16:26

I have written a couple layout files where I used the layout_weight attribute to create a ratio between different views.

At some point, I start getting

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 17:08

    Nested weights are bad for performance because:

    Layout weights require a widget to be measured twice. When a LinearLayout with non-zero weights is nested inside another LinearLayout with non-zero weights, then the number of measurements increase exponentially.

    It's better to use RelativeLayouts and adjust your view according to the places of other views without using specific dpi values.

提交回复
热议问题