Aug 5, 2011

Android Layout Optimize (layoutopt)

Android has many command-line tools available in platform-tools folder. "layoutopt" is one of them. Many time we take layout inside layout and never think about optimization of UI. Our main fous to achieve the final output. layoutopt tool allow us to verify our layout and suggest the change (if any). layoutopt is command-line tool. layoutopt analyze XML files.

1. Open Terminal
2. Go to Android-SDK/platform-tools/


To run layoutopt against a given list of layout resources:
layoutopt <file_or_directory> ...
For example:

$ layoutopt samples/
samples/compound.xml
   7:23 The root-level <FrameLayout/> can be replaced with <merge/>
   11:21 This LinearLayout layout or its FrameLayout parent is useless
samples/simple.xml
   7:7 The root-level <FrameLayout/> can be replaced with <merge/>
samples/too_deep.xml
   -1:-1 This layout has too many nested layouts: 13 levels, it should have <= 10!
   20:81 This LinearLayout layout or its LinearLayout parent is useless
   24:79 This LinearLayout layout or its LinearLayout parent is useless
   28:77 This LinearLayout layout or its LinearLayout parent is useless
   32:75 This LinearLayout layout or its LinearLayout parent is useless
   36:73 This LinearLayout layout or its LinearLayout parent is useless
   40:71 This LinearLayout layout or its LinearLayout parent is useless
   44:69 This LinearLayout layout or its LinearLayout parent is useless
   48:67 This LinearLayout layout or its LinearLayout parent is useless
   52:65 This LinearLayout layout or its LinearLayout parent is useless
   56:63 This LinearLayout layout or its LinearLayout parent is useless
samples/too_many.xml
   7:413 The root-level <FrameLayout/> can be replaced with <merge/>
   -1:-1 This layout has too many views: 81 views, it should have <= 80!
samples/useless.xml
   7:19 The root-level <FrameLayout/> can be replaced with <merge/>
   11:17 This LinearLayout layout or its FrameLayout parent is useless


Reference Article.
1. http://developer.android.com/guide/developing/debugging/debugging-ui.html#layoutopt
2. http://mobile.tutsplus.com/tutorials/android/android-sdk-tools-layout-optimization/