2011-01-24 34 views
1

Hy!在視圖的按鈕處繪製按鈕

我想在按鈕上有一個按鈕,並在一個線性佈局的視圖中居中。

非工作例如:

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:id="@+id/login_btnew" android:text="Make a new Account"></Button> 

解決方案?

感謝

回答

2

你可能想嘗試以下RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 


<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:id="@+id/login_btnew" 
    android:text="Make a new Account"></Button> 

</RelativeLayout> 
0

我這樣做,例如以下列方式:

我中有你在上面提到的線性佈局我已經滾動視圖,並在底部我有個按鈕。對於滾動視圖使用android:layout_weight =「1000」,對於按鈕使用android:layout_weight =「1」可得到所需的結果。使用android中心按鈕:layout_gravity =「center_horizo​​ntal」

希望有所幫助。

0

使用此

<Button android:id="@+id/login_btnew" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" android:text="Make a new Account" 
android:layout_gravity="bottom"/> 
0

您有layout_weight工作,並把在另一個LinearLayout中的布點。

你可以做某事像(僞代碼)

<linearlayout layout_height=fill_parent layout_with=fill_parent> 
    #the "top" fields 
    <linearlayout layout_height=fill_parent layout_with=fill_parent layout_weight=1> 
     <elem1/><elem2/><elem3/> 
    </linearlayout> 
    #the bottom field (button) 
    <button layout_height=wrap_content layout_with=wrap_content layout_gravity=center_horizontal gravity=center ></button> 
</linearlayout>