Android 嵌套布局
我是android布局的新手,请告诉我使用嵌套布局而不是使用下面的布局,上面的布局,布局右侧,组件相对布局的布局左侧属性时应用程序的性能如何.
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.
例如:
<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
有些布局只能通过进行某种程度的嵌套才能完成.但是你应该避免有太多嵌套的 LinearLayouts,更重要的是不要嵌套带有权重的 LinearLayouts.您可以在官方文档中阅读更多关于优化布局的信息.
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.
我个人将 LinearLayouts 用于简单的东西,并在布局变得更复杂时开始使用 RelativeLayout.没有一个答案,因为这是一个偏好问题.
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.