2012-10-18 44 views
1

我們使用eclipse開發android應用程序,我們只是想創建3個互相連接的按鈕。這是MyActivity .xml,這個看起來像這樣,但是我們想要按鈕需要按鈕而沒有空間。如何創建3個連接的按鈕?

<Button 
     android:id="@+id/button1 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="0dp" 
     android:layout_marginLeft="0dp" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/button1" 
     android:layout_alignBottom="@+id/button1" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="0dp" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="Button" /> 

這裏是圖像

Valid XHTML

回答

2

您可以爲此設置保證金。

<Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/button1" 
     android:layout_alignBottom="@+id/button1" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="-10dp" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="Button" /> 

設置減去保證金並檢查您的結果。

2

使用帶有按鈕的LinearLayout。

<LinearLayout 
    <Button/> 
    <Button/> 
    <Button/> 
/> 

,那麼你可以對齊的LinearLayout如你所願(中心,右,左,...)

0

使用的RelativeLayout和中心它 那麼的RelativeLayout內,創建3個按鈕(按鈕1,按鈕2, BUTTON3) 和爲其提供以下屬性:
1- button1的
alignParentLeft =真,以TotheLeftOf = BUTTON2
2- BUTTON2:
toTHeRightOf =按鈕1,totheLeftOf = BUTTON3
3- button3:
totheRightOf = button2,alignparentRight = true。

希望這就是幫助

0

只是在每一個按鈕,使用這樣android:layout_weight="1"

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button1" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button2" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button3" /> 
</LinearLayout>