Android Layout file optimization

Source: Internet
Author: User

Performance Optimization 1--ui optimization

1. Using the system gives us a few abstract tags
①include: Reusing
The Include Layout property specifies an external layout file that does not have to be repeated in this code.
If the include specifies this attribute for other android:layout_*, then layou_width and layout_height must exist. Otherwise, the other cannot take effect.

②viewstub: Load on Demand
The viewstub tag is similar to the include tag, and is used to load a layout using the Layout property. The difference is that the include tag is used to reuse the layout, which is loaded into memory when the app starts loading. The layout referenced by the viewstub tag will not be loaded, and will only be loaded when you need it at some point, saving CPU load time and memory when parsing layout.
Its meaning is to load the required layout files as needed, in actual development, there are a lot of layout files in the normal circumstances do not need to display, when the need for their display is displayed. For example, the layout of the network loading animation, this time there is no need to load the entire interface when it is initialized, through the viewstub can be used in the time of loading. Improved program performance.
Load Code on Demand:
((viewstub) Findviewbyid (R.id.stub_import)). Setvisibility (view.visible);
Or:
View Importpanel = ((viewstub) Findviewbyid (R.id.stub_import)). Inflate ();


Before I saw many friends on the Internet, said to set the view visibility to gone. The view is also not loaded into memory. In fact, this statement is wrong. From the Android source can be known, even if the view of the visiablity set to Gone,view will also be loaded in memory resources. That is, only viewstub loaded layout will not be loaded into memory resources until the app is launched.


③merge: Reduce the number of layout layers

1
The Merge tab is used to cancel the display of the layout hierarchy. As we all know, the root layout of Android top layout decorview is let framelayout. At this point in our layout, if we use the framelayout, it will cause the layout node to overlap the level overlay repeatedly draw. Android provides us with a call to hierarchy Viewer to view the layout node information. The tool is in the Sdk/tools directory.

Android Layout file optimization

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.