2013-08-06 29 views
0

我使用水平LinearLayout將設備屏幕的矩形塊分成3個相等的部分。這是使用權重完成的。這樣做的目的是並排放置3個按鈕,一個設置按鈕,一個幫助按鈕和一個聯繫人按鈕。據我所知,由於LinearLayout的層次結構規則,應該遵循LinearLayout中的第一個按鈕位於左側,下一個位於中間,最後一個位於右側。這是Visual Editor也顯示的內容。但是當我運行該應用程序(並且我嘗試了多個設備)時,聯繫人按鈕將在左邊結束,設置按鈕結束於中間,幫助按鈕結束於右側。我嘗試改變代碼的層次結構(即,我將聯繫人按鈕的代碼放在設置按鈕的代碼上方等),但它對結果沒有任何影響。 LinearLayout的代碼如下。任何幫助表示讚賞。謝謝。Android:按鈕在運行時交換水平加權LinearLayout?

<LinearLayout 
    android:id="@+id/icons" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="100"> 

    <ImageButton 
     android:id="@+id/settings" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="33" 
     android:src="@drawable/settings" /> 

    <ImageButton 
     android:id="@+id/help" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="33" 
     android:src="@drawable/help" /> 

    <ImageButton 
     android:id="@+id/contact" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="33" 
     android:src="@drawable/contact" /> 

</LinearLayout> 

回答

1

XML沒有什麼錯誤。如果應用程序真正使用上述XML,那麼更改佈局中ImageButton的順序應該確實會改變屏幕上的順序。

這裏有兩件事情浮現在腦海:

  1. 沒有與您的構建/運行過程中存在問題,當你運行你的應用程序更新的代碼更改不會反映。我建議對一些明顯的字符串資源進行更改,並測試這是否是問題。以防萬一,你也應該做一個乾淨的構建。
  2. 您有多個具有相同名稱的佈局文件(例如,一個佈局爲/,另一個佈局爲land /),而且您沒有更改正確的名稱。
+0

+1僅用於「乾淨構建」 – Geobits

+0

謝謝。清理構建工作。 Eclipse有時候可能很奇怪... –