Optimization 1-layout optimization, optimization 1-Layout Optimization
1. Reduce the nested layout. You can delete useless controls at a level.
If ViewGroup is selected, for example, RelativeLayout, if LinearLayout can be used in the layout, select the LineaLayout layout as much as possible. If FrameLayout can be used, FrameLayout should be used as much as possible, the frame layout is the fastest layout among the five major la S. It does not need to calculate the size of the control, but only needs to cover one layer of the control. Reduce the nested hierarchy of the layout. You can use a layer of layout nesting to complete the effect.
2. When there is a layout repeat, do you extract it? Use the <include> label to specify the reusable layout, the <merge> label, and the ViewStub label
The layout attribute in include specifies an external layout file. In this way, you do not need to repeat this layout file in the code.
If include specifies other android: layout _ * attributes, layou_width and Layout_height must exist. Otherwise, others cannot take effect.
② Merge Tag:
More use with <include> labels to reduce the layout level: if the current layout is a vertical LinearLayout, in this case, if LinearLayout is also used in the included layout file, we can use the Merge tag to reduce the nested hierarchy of the layout.
Inherited from the View, the light-weight width and height are 0, so he does not participate in any layout and Painting Process.
It means to load the layout files as needed. In actual development, many layout files do not need to be displayed normally, it is displayed only when it is displayed. For example, when loading the animation layout on the network, there is no need to load the animation during the initialization of the entire interface. Through ViewStub, you can load the animation during use. Improves program performance.
<ViewStub android:id="@+id/stub_import" android:inflatedId="@+id/panel_import" android:layout="@layout/layout_network_error" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gavity="bottom" />
Load the code as needed: (ViewStub) findViewById (R. id. stub_import )). setVisibility (View. VISIBLE); or: View importPanel = (ViewStub) findViewById (R. id. stub_import )). inflate ();