[英]Android: Buttons swapping place at runtime in horizontal, weighted LinearLayout?
我正在使用水平LinearLayout將設備屏幕的矩形塊分為3個相等的部分。 這是通過權重實現的。
這樣做的目的是並排放置3個按鈕,一個設置按鈕,一個幫助按鈕和一個聯系人按鈕。 據我所知,由於LinearLayout的層次結構規則,LinearLayout中的第一個按鈕位於左側,下一個按鈕位於中間,最后一個按鈕位於右側。
這就是可視編輯器還顯示的內容。 但是,當我運行該應用程序(並在多種設備上嘗試過)時,聯系按鈕最終出現在左側,設置按鈕最終出現在中間,幫助按鈕最終出現在右側。
我嘗試更改代碼的層次結構(即,將“聯系人”按鈕的代碼放置在“設置”按鈕的代碼上方,等等),但這對結果沒有任何影響。
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>
XML沒有錯。 如果應用程序確實在使用上述XML,則更改布局中ImageButton的順序實際上應該會更改屏幕上的順序。
這是我想到的兩件事:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.