Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android nested layouts

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

like image 531
mini Avatar asked Mar 14 '13 08:03

mini


People also ask

What is nested linear layout in Android?

Android LinearLayout In this layout we have a Parent LinearLayout which has a vertical orientation and contains buttons, textviews and a nested Linear Layout(having a horizontal orientation) as child views.

Which has better performance LinearLayout or RelativeLayout?

You will find that there're a lot of different, if your Pages loading some images from internet. In this case the LinearLayout is 100% better than RelativeLayout ever.

Is Constraintlayout faster than LinearLayout?

More complex layout but results are the same, flat Constraint Layout is slower than nested Linear Layout. I want to pay attention to 2 more things which are more subjective. Creating Constraint Layout takes more time than other layouts. Also introducing changes in existing Constraint Layout is much more time-consuming.

Which layout is best for large hierarchies?

Consider using flatter layouts such as RelativeLayout or GridLayout to improve performance. The default maximum depth is 10.


1 Answers

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.

like image 184
Warpzit Avatar answered Oct 10 '22 01:10

Warpzit