2013-03-25 111 views
1

我在構建Android按鈕欄樣式時遇到了一些問題。給我的每個按鈕賦予0的寬度和1的權重後,兩個按鈕之間仍有大約1px的間隙(請參見圖片)。Android按鈕欄 - buttonBarButtonStyle在按鈕之間留下間隙

什麼是擺脫這種差距的最佳途徑?爲什麼它在那裏開始呢?

<LinearLayout 
    android:id="@+id/button_bar" 
    style="?android:attr/buttonBarStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignRight="@+id/details_scroll_view" 
    android:paddin="0dp" > 

    <Button 
     android:id="@+id/button1" 
     style="?android:attr/buttonBarButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/button_dark_blue" 
     android:text="button1" 
     android:textColor="@color/text_color" /> 

    <Button 
     android:id="@+id/button2" 
     style="?android:attr/buttonBarButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/button_light_blue" 
     android:text="button2" 
     android:textColor="@color/text_color" /> 
</LinearLayout> 

[按鈕欄] [1] http://i.stack.imgur.com/9Kwf4.png

+0

退房http://developer.android.com/samples/BorderlessButtons/res/layout/sample_main.html#l71也 – 2015-01-20 12:25:15

回答

0

如果您使用的RelativeLayout代替LinearLayout那麼你可以使用像

<Button 
     android:id="@+id/button2" 
     style="?android:attr/buttonBarButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@drawable/button_light_blue" 
     android:text="button2" 
     android:textColor="@color/text_color" 
     android:layout_toRightOf="@+id/button1" /> //this will put the left edge of this button at the right edge of button1 
+0

我仍然希望保持按鈕的權重相等,寬度相等。 layout_weight爲1的寬度爲0dp的居中函數似乎只適用於線性佈局。相對佈局確實可以消除間隙... – 2013-03-25 01:33:27

+0

您仍然可以保持居中和相同的大小。 – codeMagic 2013-03-25 02:07:57

0

這將只改變按鈕的大小。您需要使用layout_margin屬性,像這樣:

android:layout_marginLeft=<insert value here> 
+0

很hackish,但它看起來像下面的作品:'android:layout_marginLeft =「 - 1dp」 ' – 2013-03-25 01:44:21

0

你所看到的空間實際上是一個分頻器。 要隱藏的分隔,只需添加

android:showDividers="none" 

LinearLayout

相關問題