2011-03-27 2 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> 

コードが正しいか間違っているかどうかを教えてください。画面中央の2列2列に4つのボタンを作成する方法

答えて

3

だからこそ!

まず、テーブルレイアウト全体を次のビューに配置する必要があります。

android:layout_centerInParent="true" 

そして最後にテーブルレイアウトandroid:layout_width="fill_parent"

android:layout_width="wrap_contentに簡単に変更します。これは、あなたが

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

をしたい場合は、あなたのテーブルにだけ広告には、次のatributeをレイアウトルートビューすることができ!

+0

貴重なご意見ありがとうございました – sarva

+0

次の行をテーブルレイアウトに追加することもできます android:layout_centerHorizo​​ntal = "true" android:layout_centerVertical = "true" –

関連する問題