0

我在 XML 中设置了以下布局,它被设置为对话框的内容视图,我想要做的是将两个按钮居中,以便它们出现在它们所在的表格行的中心,但无论如何我对他们做了他们留在左边。这与它在对话框中有关吗?我该如何解决?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:padding="10dip"
   android:background="#FF9E00"
   android:orientation="vertical">

   <TableLayout
       android:layout_width="fill_parent"
       android:layout_height="wrap_content">

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#A0DB84">
   <TextView android:id="@+id/creatediagtxt"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="TEST"/>
   </TableRow>

   <TableRow
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:background="#004884"> 

 <Button android:id="@+id/Button01" 
 android:layout_width="wrap_content" android:layout_height="wrap_content" 
 android:text="Cancel" android:layout_gravity="center"/>

 <Button android:id="@+id/Button02" 
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:text="Done" />

 </TableRow>

 </TableLayout>

4

1 回答 1

2

你可以玩弄layout_weight. 例如:

<TableRow
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:background="#004884"
   android:layout_weight="1"> 

 <Button android:id="@+id/Button01" 
  android:layout_width="wrap_content" android:layout_height="wrap_content" 
   android:text="Cancel" android:layout_weight="0.5"/>

 <Button android:id="@+id/Button02" 
  android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:text="Done" android:layout_weight="0.5" />

 </TableRow>
于 2012-03-17T14:24:43.417 回答