Optimization 1-layout optimization, optimization 1-Layout Optimization

Source: Internet
Author: User

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

① Include:

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.

③ ViewStub:

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 ();

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.