我是 android 布局的新手,请告诉我当使用嵌套布局而不是使用组件的相对布局的布局下方、上方布局、右侧布局、左侧布局属性时应用程序的性能如何。
例如:
<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>
感谢和问候 亚米尼
最佳答案
有些布局只能通过一定程度的嵌套来实现。但是你应该避免有太多嵌套的 LinearLayouts,更重要的是永远不要嵌套带有权重的 LinearLayouts。您可以在 official docs 中阅读更多关于优化布局的内容。 .
我个人对简单的东西使用 LinearLayouts,当布局变得更复杂时开始使用 RelativeLayout。没有唯一的答案,因为这是一个偏好问题。
关于Android 嵌套布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15404552/