2012-09-17 43 views
0

我在屏幕底部有5個按鈕(分組在一個線性佈局中,每個權重爲1,截圖中b1-b5上方的那一行)。但是,當文本不止一行時,該特定按鈕被按下,甚至在其父項之外。每個按鈕的高度均爲設定值,對所有按鈕均相同。 next >按鈕是處於正確位置的唯一按鈕。下面的一些XML,但似乎一切正常對我說:當文本不適合時按下Android按鈕

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/h" 
    android:orientation="horizontal" > 

    <Button         } 
     android:layout_width="0dp"    } 
     android:layout_height="@dimen/h"  } x5 
     android:layout_weight="1"/>   } 
</LinearLayout> 

的LinearLayout中從按鈕B1-B5具有10dp的margin_top。

的屏幕截圖:

screenshot http://imageshack.us/a/img441/2878/device20120917163138.png

紅線是在按鈕應該對齊。藍線是兩行文字按鈕,綠色爲3.

根據屏幕截圖,按鈕按下的位置越多,它們包含的文本行越多。如果包含太多文本的按鈕如何停止按下?在XML完整的(雖然縮短)XML

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="0dp" 
    android:paddingLeft="6dp" 
    android:paddingRight="6dp" 
    android:paddingTop="6dp"> 
    <LinearLayout 
     android:id="@+id/panel1" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/h" 
     android:layout_alignParentBottom="true" 
     android:layout_marginTop="@dimen/margin" 
     android:layout_centerHorizontal="true"> 
     <Button 
      android:layout_width="0dp"  } 
      android:layout_height="@dimen/h" }x5 
      android:layout_weight="1"/>  } 
    </LinearLayout> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_above="@+id/text" 
     android:layout_alignParentTop="true"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical" 
      android:background="@color/black" 
      android:textColor="@color/white" 
      android:text="@string/longtext"> 
     </TextView> 
    </ScrollView> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/panel1" 
     android:gravity="bottom"> 

     <LinearLayout 
      android:id="@+id/panel2" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/h" 
      android:orientation="horizontal"> 

      <Button 
       android:layout_width="0dp"    } 
       android:layout_height="@dimen/h" }x5 
       android:layout_weight="1"/>    } 
     </LinearLayout> 
    </RelativeLayout> 
</RelativeLayout> 
+0

提供您的佈局文件請 – DroidBender

回答

1

,設置這個值::我不能使用的RelativeLayout,讓他們alignTop,因爲我需要他們同樣加權

編輯android:baselineAligned="false"。狠狠地說,這與你期望的做法相反。

+0

謝謝,這很好地工作 – stealthjong