How does setting baselineAligned to false improve performance in LinearLayout?

后端 未结 3 900
青春惊慌失措
青春惊慌失措 2020-12-22 19:22

I was just building some UI in xml, and Lint gave me a warning and said to set android:baselineAligned to false to improve performance in ListView.

The docs for the

3条回答
  •  时光说笑
    2020-12-22 19:57

    // Baseline alignment requires to measure widgets to obtain the
                    // baseline offset (in particular for TextViews). The following
                    // defeats the optimization mentioned above. Allow the child to
                    // use as much space as it wants because we can shrink things
                    // later (and re-measure).
                    if (baselineAligned) {
                        final int freeSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
                        child.measure(freeSpec, freeSpec);
                    }
    

    https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/LinearLayout.java#L1093

提交回复
热议问题