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