Uncategorized

Android Developers – Optimize Your Layouts

11

“Writing user interface layouts for Android applications is easy, but it can sometimes be difficult to optimize them. Most often, heavy modifications made to existing XML layouts, like shuffling views around or changing the type of a container, lead to inefficiencies that go unnoticed.

Starting with the SDK Tools Revision 3 you can use a tool called layoutopt to automatically detect common problems. This tool is currently only available from the command line and its use is very simple – just open a terminal and launch the layoutopt command with a list of directories or XML files to analyze:

$ 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

For each analyzed file, the tool will indicate the line numbers of each tag that could potentially be optimized. In some cases, layoutopt will also offer a possible solution.
The current version of layoutopt contains a dozen rules used to analyze your layout files and future versions will contain more. Future plans for this tool also include the ability to create and use your own analysis rules, to automatically modify the layouts with optimized XML, and to use it from within Eclipse and/or a standalone user interface.”
[Via Android Developers]

Phases

Sony Ericsson J10 Coming To GreenHeart?

Previous article

Motorola Milestone Commercial Falls Way Short Of Droid Campaign

Next article

You may also like

11 Comments

  1. can’t they just integrate it into the eclipse ADT plugin?

  2. Forgive me if I am missing something, but is this post a copy/paste of the original article on dev blog? My understanding is that Google frowns upon that for search relevancy. Might be hurting yourself.

  3. @lordhong, Can you just read the post completely?

    See the last sentence.

  4. Buxdroid: yes it is. On occasion we do that for whatever rushed reason. Sometimes rather just get the news to you then try to formulate some sort of thought around it. But, I do hate doing it and sigh every time I do.

    I will try to improve..

    Thanks for the feedback.

  5. Buxroid,

    Screw that, you copy/paste do whatever you gotta do to get the message to us and quickly.

  6. one of the annoying things in developing an app for an Android is writing the xml layouts files. They need to make it easier, i dont know how, maybe looking at netbeans form builder source would give them an idea

  7. you know…you dont have to use layout files. you can always instantiate controls programmatically.

  8. What Android needs is a good WYSIWYG design tool for the UIs. There is no reason why it can’t be done and I’m sure with the flood of companies moving to Android there would be some good money in it.

  9. How abt DroidDraw? Seems like a good open source project for developers to build upon..

  10. DroidDraw is really good if you are a capable developer with some sense for designing UI. I have seen quite a few good developers who are brain-dead when it comes to UI design.

    For example, I’m brain-dead when it comes to making it look fancy (say, animations, color choice, etc) but my UIs are generally functional and work well with varying screen sizes.

  11. @talton

    Besides being frowned upon by Google, it’s also pretty half-assed blogging. You should at least throw a few original words in there, and use a block quote.

Leave a reply

Your email address will not be published. Required fields are marked *