style="@android:style/buttonbar",Android Button Bar - buttonBarButtonStyle leaves gap between button...

问题

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值