2012-02-02 36 views
2

enter image description here我改變重心,但按鍵位置相同

你能解釋一下爲什麼請我改變重力它沒有改變。首先當我改變它的按鈕位置被改變,但現在我不能改變位置。

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="92dp" 
     android:layout_height="0dp" 
     android:layout_gravity="right" 
     android:layout_weight="1" 
     android:text="@string/button1" /> 

</LinearLayout> 
+2

請出示XML。 – 2012-02-02 12:26:47

+0

郵政一些代碼,它是幫助repley ... – NagarjunaReddy 2012-02-02 12:28:15

+0

烏拉圭回合後的XML代碼... – himanshu 2012-02-02 12:28:44

回答

2

設置該屬性相關佈局的android:layout_width = 「match_parent」的LinearLayout中 (父佈局)

+0

謝謝你的作品 – 2012-02-02 12:34:53

+0

爲什麼沒有這種自動當我改變了這種從圖形佈局變化? – 2012-02-02 12:36:51

0

我的猜測是,你需要設置屬性父佈局的「layout_width」(即包含該按鈕的的LinearLayout)至FILL_PARENT。

1

要設置按鈕,這將導致在設置你的視圖的佈局重心。例如,如果您有按鈕文本,並設置重心,那麼將中心對齊文本到按鈕,設置組件的重心到父,你需要設置家長的重力。

所以你的代碼更改爲:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="right" 
    android:orientation="vertical" > 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="92dp" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/button1" /> 

</LinearLayout>