问题
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?
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" >
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" />
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" />
[button bar][1]
http://i.stack.imgur.com/9Kwf4.png
回答1:
If you use a RelativeLayout instead of LinearLayout then you can use something like
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
回答2:
This will only change the size of the button. You need to use the layout_margin attribute, like this:
android:layout_marginLeft=
回答3:
The space you are seeing is actually a divider.
To hide those dividers, just add
android:showDividers="none"
to the LinearLayout.
来源:https://stackoverflow.com/questions/15606212/android-button-bar-buttonbarbuttonstyle-leaves-gap-between-buttons