2

I'm having some trouble with the built in Android button bar styling. After giving a width of 0 and weight of 1 to each of my buttons, there's still about a 1px gap in between the two buttons (see image).

What is the best way to get rid of that gap? Why is it even there to begin with?

<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>

[button bar][1] https://i.stack.imgur.com/9Kwf4.png

Collin Buchan
  • 257
  • 1
  • 3
  • 9

3 Answers3

0

This will only change the size of the button. You need to use the layout_margin attribute, like this:

android:layout_marginLeft=<insert value here>
crazylpfan
  • 1,038
  • 7
  • 9
0

If you use a RelativeLayout instead of LinearLayout then you can use something like

 <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
codeMagic
  • 44,549
  • 13
  • 77
  • 93
  • I still would like to preserve equal weighting for the buttons, with equal width. The centering function of layout_weight of 1 with width of 0dp only appears to work for linear layouts. Relative layout does remove the gap though... – Collin Buchan Mar 25 '13 at 01:33
  • You can still keep them centered and the same size. – codeMagic Mar 25 '13 at 02:07
0

The space you are seeing is actually a divider. To hide those dividers, just add

android:showDividers="none"

to the LinearLayout.

Antimonit
  • 2,846
  • 23
  • 34