2013-03-14 95 views
7

我是新来的android布局,可以请告诉我,当使用嵌套的布局,而不是使用下面的布局,上面的布局,布局的权利,组件的相对布局左布局的应用程序的性能。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> 

感谢&问候 雅米妮(Yamini)

回答

9

那么一些布局只能通过做一些嵌套级别。但是,您应该避免嵌套LinearLayouts过多,甚至更重要的是不要将LinearLayouts与权重嵌套在一起。您可以阅读更多关于优化official docs中的布局的内容。

就我个人而言,我使用LinearLayouts进行简单的操作,并在布局变得更复杂时开始使用RelativeLayout。没有人会回答,因为这是一个偏好问题。

+0

这对于在滚动完成时需要重新绘制多次视图的列表而言尤为重要。 – 2017-09-22 11:50:15

2

会强烈建议你这就是所谓的层次结构查看器工具。它与SDK捆绑在一起,你可以在android-sdk/tools目录下找到它。简而言之,它通过测量需要处理的时间来帮助发现布局中的问题。 Hierarchy Viewer的更广泛描述可以在here找到。希望这可以帮助。