Alex Rivera | Logout

How to center icon and text in a android button with width set to "fill parent"

Asked 2010-09-03T08:43:28.873
151

I want to have an Android Button with icon+text centered inside it. I'm using the drawableLeft attribute to set the image, this works well if the button has a width of "wrap_content" but I need to stretch to max width so I use width "fill_parent". This moves my icon straight to the left of the button and I want both icon and text centered inside the button.

I've try setting up the padding but this only allows to give a fixed value so it is not what I need. I need to have icon+text aligned in the center.

<Button 
    android:id="@+id/startTelemoteButton" 
    android:text="@string/start_telemote"
    android:drawableLeft="@drawable/start"
    android:paddingLeft="20dip"
    android:paddingRight="20dip"            
    android:width="fill_parent"
    android:heigh="wrap_content" />

Any suggestions on how I could achieve that?

Edit
Report

2 Answers

1

What happens if you try android:gravity="center_horizontal"?

answered 2011-01-12T21:34:33.033
0

I think android:gravity= "centre" should work

answered 2011-10-04T10:42:55.770

Your Answer