簡體   English   中英

Android:按鈕在運行時在水平的加權LinearLayout中交換位置?

[英]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的順序實際上應該會更改屏幕上的順序。

這是我想到的兩件事:

  1. 您的構建/運行過程存在問題,並且在您運行應用程序時更新的代碼更改不會反映出來。 我建議更改一些明顯的字符串資源,然后測試這是否是問題所在。 您還應該進行干凈的構建,以防萬一。
  2. 您有多個具有相同名稱的布局文件(例如,一個在layout /中,另一個在layout-land /中),而您沒有更改正確的文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM