2011-10-16 28 views
0

我想使按鈕佔用每個對話框寬度的一半,謝謝x3。 enter image description here 如何使按鈕分享一半在android中的對話框的寬度?

<RelativeLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:paddingBottom="10dp" 
    android:paddingLeft="10dp" android:paddingRight="10dp"> 
    <TextView android:layout_width="fill_parent" 
     android:layout_height="1dip" android:background="#FFFFFF" android:id="@+id/seperator_line" /> 
    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/text1" 
     android:text="Amount:" android:textColor="#FFFFFF" 
     android:layout_below="@id/seperator_line" android:padding="10dp" /> 
    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/deleteButton_dialog" 
     android:layout_below="@id/text1" android:text="Delete" /> 
    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/cancelButton_dialog" 
     android:text="Cancel" android:layout_toRightOf="@id/deleteButton_dialog" 
     android:layout_below="@id/text1" /> 
</RelativeLayout> 

+0

發佈您的代碼和圖片,如果可以的話。如果沒有更多的東西可以解決,那麼任何人都不可能告訴你發生了什麼。 – FoamyGuy

+0

螺絲它大聲笑il只是做一個textview而不是 –

+0

我改變了這個問題,你可以幫助那個嗎?謝謝x333 –

回答

1

您可以將它們放置在一個LinearLayout中,然後將寬度設置爲 「FILL_PARENT」 和layout_weight爲 「1」。像這樣:

<LinearLayout android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_below="@id/text1"> 
    <Button android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:id="@+id/deleteButton_dialog" 
      android:text="Delete" /> 
    <Button android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:id="@+id/cancelButton_dialog" 
      android:text="Cancel"/> 
</LinearLayout> 
+0

lol歡呼,但是當我把這個線性佈局在我的相對佈局下,整個對話框的所有內容消失:( –

+0

你將不得不使用包裝XML,但如果你發佈了新的佈局,我可以嘗試幫助 – hooked82