2011-03-27 65 views
0
<TableLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/TableLayout01" 
    android:layout_height="wrap_content" android:layout_width="fill_parent"> 
    <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 

     <Button android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="Settings" 
      android:id="@+id/btnSettings"></Button> 
     <Button android:text="@+id/Button01" android:id="@+id/Button01" 
      android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>   
    </TableRow> 
    <TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <Button android:text="@+id/Button03" android:id="@+id/Button03" 
      android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
     <Button android:text="@+id/Button04" android:id="@+id/Button04" 
      android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 

    </TableRow> 
</TableLayout> 

請給出建議,代碼是對還是錯?如何在屏幕中心創建4行2列和2列的按鈕

回答

3

太近了!

首先你需要把整個表格佈局放在下面的視圖中。這可能是你的根視圖如果你想

<RelativeLayout android:layout_width="fill_parent" android:id="@+id/relativeLayout1" android:layout_height="fill_parent"> 

然後,只需使廣告與表格的佈局以下屬性附加傷害:

android:layout_centerInParent="true" 

終於在表格佈局改變android:layout_width="fill_parent"android:layout_width="wrap_content

易!

+0

感謝您的寶貴意見 – sarva 2011-03-27 09:37:31

+0

您還可以將以下幾行添加到表格佈局 android:layout_centerHorizo​​ntal =「true」 android:layout_centerVertical =「true」 – 2014-09-15 16:02:42