2012-03-17 44 views
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> 

回答

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> 
+0

非常感谢你,我nevr之前使用过体重。 – nexus490 2012-03-17 14:30:17

+0

好答案亲爱的。 – Hasmukh 2012-03-17 14:37:22