2011-04-28 109 views
2

我不知道如何嵌套不同的布局。 我想要一个listlayout和一个表格布局并排。我想ListLayout左和表布局上listlayout的右侧例如嵌套不同的布局

<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和表格布局上左边。我只是一个初学者,可能是我完全错了。任何人都可以引导我,请其紧急....

回答

1

您可以开始与ScrollView或TableLayout作为最高的父。如果它是一个TableLayout,那么你需要一个TableRow。

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

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

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

1

您需要有一个整体布局,然后在其中放置子布局。一种做你想做的事的方法是将顶层布局设置为水平方向的LinearLayout。需要注意的一点是,随着您添加越来越多的布局,性能会有所下降,所以尝试最小化布局数量是个好主意。

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的,它可以让你指定sublayouts相对于其他sublayouts定位。例如: http://www.tutorialforandroid.com/2009/01/relativelayout-in-android-xml.html

+0

我试图把代码i的RelativeLayout的上述显示但它没有帮助:( – Jeena 2011-04-28 14:57:09

+0

@Jeena,当使用RelativeLayout时,你必须告诉对象在哪里放置themselv es,使用“below”,“toRightOf”,“toLeftOf”等。 – 2011-04-29 16:59:56

0

如果您使用了相对布局,那么在xml文件中使用表和列表视图的以下参数。 对于ListView控件 - >机器人:layout_alignParentLeft = “真” 和TableView中, - >机器人:为layout_alignParentRight = “真” :layout_toRightOf = “ListView控件” 此外,如果这也不行,再添加一个 机器人的tableView