Android Lint gives us warning when we do nested weights saying that nested weights are bad for performance so i was wondering what will happen if i add an extra layout which encloses the nested weigh layouts. Will it make any difference in performance?
The guy here said that 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.
So i was wondering is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/fl_topleft"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shape" />
<FrameLayout
android:id="@+id/fl_topright"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shape" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/fl_bottomleft"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shape" />
<FrameLayout
android:id="@+id/fl_bottomright"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shape" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Better than
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:layout_weight="1" >
<FrameLayout
android:id="@+id/fl_topleft"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shape" />
<FrameLayout
android:id="@+id/fl_topright"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shape" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:layout_weight="1" >
<FrameLayout
android:id="@+id/fl_bottomleft"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shape" />
<FrameLayout
android:id="@+id/fl_bottomright"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/shape" />
</LinearLayout>
</LinearLayout>