How does Android use layoutopt to check whether the layout file is reasonable?

Source: Internet
Author: User

In Android development, layout files are generally indispensable. Poor layout files, such as unnecessary nesting, excessive views, and too deep nesting, can easily cause excessive system overhead, program anp and so on. How can I preliminarily check whether a layout file is reasonable? In addition to some of the general rules we have implemented in the project, the sdk also contains a layoutopt command line tool to help us analyze the rationality of the layout file. How to use it?
On the window platform, you can use layoutopt. bat to quickly use the layoutopt analysis function. The bat file is located in the android-sdk-windows \ tools directory.

Assume that the directory of this file is F: \ Work \ Tool \ Android \ android-sdk-windows \ tools.

1. Go to the layoutopt. bat directory.

1) run win + r and Enter cmd.

2) Go to the tool directory.


[Plain]
C: \ Documents ents and Settings \ administrator> cd/d F: \ Work \ Tool \ Android \ android-sdk-
Windows \ tools
 
F: \ Work \ Tool \ Android \ android-sdk-windows \ tools>
2. Check the layout file E: \ Code \ git \ Camera \ res \ layout \ viewitem. xml.

[Plain]
F: \ Work \ Tool \ Android \ android-sdk-windows \ tools> layoutopt. bat E: \ Code \ git \ Camera \ res \ layout \ viewitem. xml
E: \ Code \ git \ Camera \ res \ layout \ viewitem. xml

If the layout file is valid, the preceding result is displayed.
If it is invalid, it will be shown as follows:


[Plain]
F: \ Work \ Tool \ Android \ android-sdk-windows \ tools> layoutopt. bat E: \ Code \ git \ Camera \ res \ layout \ viewlist. xml
E: \ Code \ git \ Camera \ res \ layout \ viewlist. xml
35: 42 This tag and its children can be replaced by one <TextView/> and
Compound drawable
46: 53 This tag and its children can be replaced by one <TextView/> and
Compound drawable
57: 64 This tag and its children can be replaced by one <TextView/> and
Compound drawable
F: \ Work \ Tool \ Android \ android-sdk-windows \ tools>

The preceding number is the number of rows.
3. Import the directory where the layout file is located to check the layout files in batches.


[Plain]
F: \ Work \ Tool \ Android \ android-sdk-windows \ tools> layoutopt. bat E: \ Code \ git \ Camera \ res \ layout

With related tips, we can easily find out inefficient and useless la S and optimize them accordingly. Of course, sometimes the prompt is not necessarily accurate and we need to make a proper choice.

From the pure soul

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.