1. 程式人生 > >Android中將layout_width或layout_height設定為0的情況

Android中將layout_width或layout_height設定為0的情況

當使用view的layout_weight屬性時,可以將layout_width設定為0,原因是這樣可以讓系統減少一次長度或寬度的計算。

官方解釋如下:

In order to improve the layout efficiency when you specify the weight, you should change the width of the to be zero (0dp). Setting the width to zero improves layout performance because using"wrap_content" as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.


示例:

    <EditText
        android:layout_weight="1"
        android:layout_width="0dp"
        ... />