user291701
user291701

Reputation: 39681

Can't get rid of bottom padding on button

I have a button. It seems to have bottom padding I cannot get rid of:

<Button
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Foo"/>

In the resource editor, I can click the button, and you see the padding below the bottom edge of the button there. This seems to block me from properly centering the button vertically in a parent RelativeLayout.

enter image description here

I tried setting padding=0dip and layout_margin=0dip, no effect. That bottom padding persists.

Thanks

Upvotes: 5

Views: 6859

Answers (4)

Devrath
Devrath

Reputation: 42824

I am late to answer this but thought to share if someone come across similar use case( Removing all the inner and outer padding in Button )

<Button
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginLeft="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="-5dp"
android:minHeight="-2dp"
android:minWidth="-2dp"
android:text="TextView"
android:textSize="12sp" />

Upvotes: 2

Archimedes
Archimedes

Reputation: 31

setting android:layout_marginBottom="-5dp" for the button worked nicely for me.

Upvotes: 3

Matthew
Matthew

Reputation: 44919

The padding is in the 9-patch of the buttons themselves.

I'd advise against trying to compensate because these graphics resources can change without notice. You'd be better off building your own 9-patch or editing the existing one to remove the padding.

Upvotes: 5

icyerasor
icyerasor

Reputation: 5242

Hmn really strange. Never noticed that. Probably because u usally want a little space around your buttons.

Also tried margin/padding=0dp and did in fact not work.

You could set android:layout_marginBottom="-10dp" however :).

Upvotes: 0

Related Questions