Android nested layouts
Asked Answered
G

2

9

I am new to android layouts, Could please tell me how the performance of application when using nested layouts instead of using layout below, layout above, layout right, layout left attributes of relative layout for components.

For eg:

<RelativeLayout>
    <scrollView>
       <RelativeLayout>
          <LinearLayout> Header<LinearLayout>
           <TextView/>  <TextView/>
           <TableLayout>
                   <TableRow><ImageView/> <TextView> <Spinner><TableRow>
                   <TableRow><ImageView/> <TextView> <Spinner><TableRow>
                   <TableRow><ImageView/> <TextView> <Spinner><TableRow>
                   <TableRow><ImageView/> <TextView> <Spinner><TableRow>
          </TableLayout>

          <TextView>
          <TableLayout>
                 <TableRow>
                    <LinearLayout> <ImageView><TextView></LinearLayout> 
                    <EditText>
                 </TableRow>
                 <TableRow>
                    <LinearLayout> <ImageView><TextView></LinearLayout>
                    <EditText>
                </TableRow>
                <TableRow>
                   <TextView> 
                   < Spinner>
                </TableRow>
                <TableRow><TextView> <Spinner></TableRow>
          </TableLayout>

           <TableLayouts>---</TableLayout>

          <LinearLayout> footer</LinearLayout>
</RelativeLayout>
<ScrollView>
</RelativeLayout>

Thanks & Regards Yamini

Graphitize answered 14/3, 2013 at 8:41 Comment(0)
L
13

Well some layouts can only be made by doing some level of nesting. But you should avoid having too many nested LinearLayouts and even more important NEVER nest LinearLayouts with weights. You can read a little more about optimizing layouts in the official docs.

Personally I use LinearLayouts for simple stuff and start using RelativeLayout when the layout gets more complex. There is no one answer as it is a matter of preference.

Latrishalatry answered 14/3, 2013 at 9:20 Comment(1)
This is particularly important in the case of lists where the views need to redrawn many times when scroll is done.Taipan
D
2

Would highly recommend you a tool that's called Hierarchy Viewer. It's bundled with the SDK and you can find it under android-sdk/tools directory. In short, it helps find problems in your layouts by measuring time that takes them to be processed. A broader description of Hierarchy Viewer can be found here. Hope this helps.

Disorganize answered 14/3, 2013 at 9:19 Comment(1)
now deprecated, developer.android.com/studio/debug/layout-inspector is the equivalent tool to useKoonce

© 2022 - 2024 — McMap. All rights reserved.