2012-03-17 43 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