2013-03-03 25 views
1

我的XML文件有問題。 我有兩個自定義大小的按鈕。 我想調整按鈕的大小相對於屏幕的大小。如何設置按鈕之間的距離?

在圖片1上,你可以看到它們應該有多大。

enter image description here

在圖片2,你可以看到,他們是太遙遠又小。

enter image description here

我知道我沒有設置是否正確。 (主要是android:layout_width)但是如何設置?

這裏是我的XML代碼:

<Button 
     android:id="@+id/button2" 
     android:layout_width="130dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:background="#99000099" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="130dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:background="#99990000" /> 

感謝您的回覆! :)

+0

你使用什麼佈局作爲它們的容器? – 2013-03-03 16:09:52

+0

發佈完整的佈局文件並更多地闡明您的問題。 – 2013-03-03 16:12:53

回答

4

如果您嘗試使用LinearLayout來包裝按鈕,可以將它放在底部,然後將按鈕的權重設置爲1,這意味着它們將佔用每個屏幕的一半。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true"> 
<Button 
    android:id="@+id/button1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:background="#99000099" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:background="#99990000" /> 
</LinearLayout> 

注意,您可以從邊緣,他們除了客場更改按鈕上的利潤率,以空間太像你的第一張照片。