Take the 2-minute tour ×

I have a relatively big XML layout (38 kB, 600 lines) with hierarchy like:

    <FrameLayout> //tab widget
     <LinearLayout> //tab content
      <LinearLayout> //section
       <TextView> //section name
       <LinearLayout orientation="horizontal"> //item 1 box
        <TextView> //item 1 title
        <Spinner> //item 1 picker
       <LinearLayout> //item 2 box
        <TextView> //item 2 title
        <Spinner> //item 2 picker
       ...  //18 other items
      ... //4 other sections with 15 items each

It is a data entry form that has to have that many items and the best I can do now is to do to wrap setContentView and loading of data to the spinners in an AsyncTask with a "Loading..." dialog.

Does extensive using of themes also slow down the view inflation? The view inflater wouldn't need to look in loaded theme.xml, but if I were to inline the theme into the layout xml, it would also increase the size of the XML considerably, thus slow down the parser.

Is there something I could do to simplify the layout that would make it load at least twice as fast? I'm thinking that I might try to get rid of the horizontal LinearLayouts, and build the "section" with TableLayout.

share|improve this question
add comment

2 Answers

First, three general comments:

  1. You really want to avoid layouts that deeply nested.
  2. Consider using RelativeLayout to replace nested LinearLayouts.
  3. Use the layout_opt tool to get some suggestions on layout optimizations.

Now, more on #1 … have you considered writing your own layout? It sounds complex at first, but it can sometimes drastically improve layout performance. For example, if RelativeLayout doesn't serve the purpose, you may be able to combine your Linear-Frame-Linear-Linear chain into a single custom layout.

Lastly, is there a reason your tab indicators are scrollable? That seems like a navigation/UX problem.

share|improve this answer
The reason the whole layout is nested in a ScrollView is that I can offer more of the screen estate for the data entry form itself. Users will very infrequently switch tabs and when they need to, there is a Menu action for that or they can scroll to the top of the screen. –  Axarydax Aug 18 '11 at 3:34
and to clarify on the FrameLayout, it's a container for the Tab content, so I just need to replace Linear-Linear-Linear chain. I will definitely read up on custom layouts, though. –  Axarydax Aug 18 '11 at 3:36
In general though, tabs should remain fixed, but that's another topic. You can find an example custom layout here: code.google.com/p/iosched/source/browse/android/src/com/google/… –  Roman Nurik Aug 18 '11 at 7:16
add comment

The only thing I can think to do would be to break your views into a couple different parts and inflate each view whenever the user gets to that part. Not sure if that helps at all but good luck.

Also might help to look at that portion of the code in traceview

share|improve this answer
add comment

Your Answer


