Optimization of Android layout optimization level

Source: Internet
Author: User

Each component and layout of the program needs to be initialized, laid out, and drawn, and if the nesting level of the layout is too deep, it can lead to more time-consuming loading operations and, more severely, memory overruns. In this section we learn to use two tools to check and optimize Layout.

Hierarchyviewer

The tool is located in Android SDK Tools and uses Hierarchyviewer to analyze the layout of the running app, breaking the bottleneck that affects layout performance.

Hierachyviewer works by selecting a process that runs on the emulator or the real machine and is displayed through the layout tree. Each of the above identities represents the performance of the layout measure, layout, and draw, helping developers to locate potential problems.

1, shown in the figure is a layout in the ListView, the layout to the left is a imageview, the right side is a linearlayout nested two textview layout.

Figure 1

The Hierarchyview tool can be used with the Android emulator, which opens to see the list of available devices and the components that are running. In the Windows tab, click Hierarchy view to see the layout hierarchy for the selected component. Example 2 shows the hierarchical structure of the ListItem layout in Figure 1.

Figure 2

Reduce hierarchy

Performance slows due to the use of nested linearlayout structure layouts. We can use flat ideas to optimize them--the layout is wide and broad, not narrow and deep! We can use Relativelayout as a top-level node, so we'll see this layout hierarchy after we move to Relativelayout to layout.

Figure 3

After modifying to Relativelayout layout, the hierarchy is reduced and layout performance is greatly enhanced. Also, layout_weight in linearlayout slows down measure, so do not use the Layout_weight attribute when necessary. This is only a small example, in some very complex layouts, if the hierarchy is too high or linearlayout nested too much, the system will consume a lot of performance on the UI measure calculation, therefore, hierarchy optimization is critical.

Lint

Android Lint is a new tool provided in ADT 16, it is a code scanning tool, lint has replaced the layoutopt tool as an important ToolTip, with more advanced features that can help us identify problems with the code structure. Some of the detection rules included in Lint are:

    • Use compound drawable instead of a linearlayout that contains ImageView and TextView.

    • Merge Root Framelayout

    • A useless child node or parent node

    • Hard-coded issues

In addition, developers can manage configuration files through File>settings>project Settings.

Optimization of Android layout optimization level

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.