2011-04-28 97 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