2014-02-06 29 views
0

我的活動屏幕創建爲垂直LinearLayout。我想將ToggleButton添加到屏幕的左側。我試着用重力參數,使它象這裏:如何向左移動ToggleButton LinearLayout

<ToggleButton 
       android:id="@+id/toggleButton1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="20sp" 
       android:gravity="left"/> 

但是它把文字上的按鈕左邊,而不是按鈕本身。如何將垂直LinearLayout中的按鈕向左移動?

+0

你想要一切左對齊嗎? – Lawrence

回答

0

考慮到你的LinearLayout是定義的android:layout_width = 「match_parent」 ...使用:

<ToggleButton 
      android:id="@+id/toggleButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:layout_gravity="left"/> 

安卓layout_gravity ==上包含此元素的佈局的對齊方式(即LinearLayout)

android:gravity ==內部元素(即Button內的文本)的對齊方式。