Android 嵌套布局

标签 android android-layout android-relativelayout nestedlayout

我是 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/

相关文章:

android - View 类中的 draw() 和 onDraw() 方法有什么区别?

Android - 实现背景效果的调光

android - 在 Android 中动态加载 ListView 时布局无法正确显示?

java - 数据库添加项目到 ListView ?

android - 如何更改选项卡布局的文本颜色?

java - 如何在Android的PreferenceScreen中使用textview?

android - android中列表的listview

android - SMS 正文并未更改其 Intent 中的文本

android - 将按钮动态放置在 RelativeLayout 中的特定位置

android - 将一个 View 置于另一个 View 之上