嵌套不同的布局

时间:2011-04-28 14:05:15

标签: android layout nested

我不确定如何嵌套不同的布局。 我希望有一个listlayout和一个表格布局并排。我想要左边的ListLayout和listlayout右边的Table布局,例如

<ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" android:focusable="true"
        android:focusableInTouchMode="true" />

和一个tablelayout

<TableLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
<TableRow>
    <TextView
        android:layout_column="1"
        android:text="Open..."
        android:padding="3dip" />
    <TextView
        android:text="Ctrl-O"
        android:gravity="right"
        android:padding="3dip" />
</TableRow>

<TableRow>
    <TextView
        android:layout_column="1"
        android:text="Save..."
        android:padding="3dip" />
    <TextView
        android:text="Ctrl-S"
        android:gravity="right"
        android:padding="3dip" />
</TableRow>
    </TableLayout>

但是,如果我这样做,那么我没有得到listlayout,表格布局在左边。我只是一个初学者,可能我完全错了。任何人都可以指导我,请它紧急....

4 个答案:

答案 0 :(得分:1)

您可以从ScrollView或TableLayout开始作为顶级父级。如果它是TableLayout,那么你需要一个TableRow。

<TableLayout>
   <TableRow>
      {Add your ListView Here}

      {Add your nested TableLayout here}
   </TableRow>
</TableLayout>

由于没有TableColumn或TableCell,它应该将TableRow中的每个子节点视为一列。

答案 1 :(得分:1)

您需要有一个整体布局,然后将子布局放在其中。实现所需目标的一种方法是使顶层布局为水平方向的LinearLayout。需要记住的一点是,随着您添加越来越多的布局,性能会有所下降,因此最好尽量减少布局的数量。

答案 2 :(得分:1)

您是否尝试过将表格和列表布局放在LinearLayout中?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent" 
              android:orientation="horizontal" >
     <!-- List view goes here -->
     <!-- Table layout goes here -->
</LinearLayout>

还有RelativeLayout,它允许您指定子布局相对于其他子布局的位置。例如: http://www.tutorialforandroid.com/2009/01/relativelayout-in-android-xml.html

答案 3 :(得分:0)

如果您使用了相对布局,则在xml文件中对表和列表视图使用以下参数。 对于ListView - &gt; android:layout_alignParentLeft =“true” 对于TableView, - &gt; android:layout_toRightOf =“ListView” 此外,如果这不起作用,请再添加一个 机器人:layout_alignParentRight = “真” for tableView

相关问题