开发者

Is there a way to completely eliminate padding in a LinearLayout containing buttons?

I tried the following to try to display two buttons in a horizontal linear layout, with the edges of the buttons flush with the border of the linear layout. To my surprise, I found that there is always still padding between the buttons and the left, right and bottom edges of the linear layout. Only the top edges of the buttons end up flush with the border of the linear layout. Why is that? And is there a way to control this behavior? Thanks much.

<LinearLayout android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#777"
  android:padding="0dip"
  android:layout_margin="0dip">
  <Button android:id="@+id/fee开发者_如何学运维ling_done_button"
     android:text="@string/done_button_label"
     android:layout_height="wrap_content"
     android:layout_width="match_parent"
     android:layout_weight="1"
     android:padding="0dip"
     android:layout_margin="0dip"/>
  <Button android:id="@+id/feeling_cancel_button"
     android:text="@string/cancel_button_label"
     android:layout_height="wrap_content"
     android:layout_width="match_parent"
     android:layout_weight="1"
     android:padding="0dip"
     android:layout_margin="0dip"/></LinearLayout>


If you're meaning you want them to be pushed to the edge, pixel for pixel, you'll need to use your own 9-patch for the button background, as the default one in Android has a few extra pixels around the border of its 9-patch background. For an example of this, look at the file in your SDK folder under:

platforms/android-8/data/res/drawable-hdpi/btn_default_transparent_normal.9.png

For example, this is what I get with the default:

Is there a way to completely eliminate padding in a LinearLayout containing buttons?

And with a custom 9-patch I had made earlier:

Is there a way to completely eliminate padding in a LinearLayout containing buttons?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜