| Dirk Dougherty | bf15ce6 | 2009-10-23 19:17:12 -0700 | [diff] [blame] | 1 | page.title=layoutopt |
| 2 | @jd:body |
| 3 | |
| 4 | <p><code>layoutopt</code> is a command-line tool that helps you optimize the |
| 5 | layouts and layout hierarchies of your applications. You can run it against your |
| 6 | layout files or resource directories to quickly check for inefficiencies or |
| 7 | other types of problems that could be affecting the performance of your |
| 8 | application. </p> |
| 9 | |
| 10 | <p>To run the tool, open a terminal and launch <code>layoutopt |
| 11 | <resources></code> from your SDK <code>tools/</code> directory. In the |
| 12 | command, supply a list of uncompiled resource xml files or directories that you |
| 13 | want to analyze. </p> |
| 14 | |
| 15 | <p>When run, the tool loads the specified XML files and analyzes their layout |
| 16 | structures and hierarchies according to a set of predefined rules. If it detects |
| 17 | issues, it outputs information about the issues, giving filename, line numbers, |
| 18 | description of issue, and for some types of issues a suggested resolution. </p> |
| 19 | |
| 20 | <p>Here's an example of the output:</p> |
| 21 | |
| 22 | <pre>$ layoutopt samples/ |
| 23 | samples/compound.xml |
| 24 | 7:23 The root-level <FrameLayout/> can be replaced with <merge/> |
| 25 | 11:21 This LinearLayout layout or its FrameLayout parent is useless |
| 26 | samples/simple.xml |
| 27 | 7:7 The root-level <FrameLayout/> can be replaced with <merge/> |
| 28 | samples/too_deep.xml |
| 29 | -1:-1 This layout has too many nested layouts: 13 levels, it should have <= 10! |
| 30 | 20:81 This LinearLayout layout or its LinearLayout parent is useless |
| 31 | 24:79 This LinearLayout layout or its LinearLayout parent is useless |
| 32 | 28:77 This LinearLayout layout or its LinearLayout parent is useless |
| 33 | 32:75 This LinearLayout layout or its LinearLayout parent is useless |
| 34 | 36:73 This LinearLayout layout or its LinearLayout parent is useless |
| 35 | 40:71 This LinearLayout layout or its LinearLayout parent is useless |
| 36 | 44:69 This LinearLayout layout or its LinearLayout parent is useless |
| 37 | 48:67 This LinearLayout layout or its LinearLayout parent is useless |
| 38 | 52:65 This LinearLayout layout or its LinearLayout parent is useless |
| 39 | 56:63 This LinearLayout layout or its LinearLayout parent is useless |
| 40 | samples/too_many.xml |
| 41 | 7:413 The root-level <FrameLayout/> can be replaced with <merge/> |
| 42 | -1:-1 This layout has too many views: 81 views, it should have <= 80! |
| 43 | samples/useless.xml |
| 44 | 7:19 The root-level <FrameLayout/> can be replaced with <merge/> |
| 45 | 11:17 This LinearLayout layout or its FrameLayout parent is useless</pre> |
| 46 | |
| 47 | <p>The <code>layoutopt</code> tool is available in SDK Tools, Revision 3 or |
| Dirk Dougherty | bca9f1b | 2009-11-18 23:06:16 -0800 | [diff] [blame] | 48 | later. If you do not have SDK Tools r3 or later installed in your SDK, you can |
| Dirk Dougherty | bf15ce6 | 2009-10-23 19:17:12 -0700 | [diff] [blame] | 49 | download it from the Android SDK repository site using the Android SDK and AVD |
| 50 | Manager. For information, see <a |
| 51 | href="{@docRoot}sdk/adding-components.html">Adding SDK Components</a>.</p> |
| 52 | |
| 53 | <h3>Usage</h3> |
| 54 | |
| 55 | <p>To run <code>layoutopt</code> against a given list of layout resources:</p> |
| 56 | |
| 57 | <pre>layoutopt <list of xml files or directories></pre> |
| 58 | |
| 59 | <p>For example:</p> |
| 60 | |
| 61 | <pre>$ layoutopt res/layout-land</pre> |
| 62 | <pre>$ layoutopt res/layout/main.xml res/layout-land/main.xml</pre> |