views:

160

answers:

2

I want to have an Android Button with icon+text centered inside it. I'm using the drawableLeft attribute to set the img, this work 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 fix 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 suggestion how could I archive that?

A: 

Try to use android:drawableTop="@drawable/start" instead. Or do you want to have the drawable on the left side of the text but centered?

Octavian Damiean
Yes I want the drawable on the left side of the text, and both centered in the button. Thanks.
A: 

It's possible that there is not an easy solution for this? Do I have to try with a 9patch button img with the icon in there?

This might be a solution. Is the button text going to be localized or static?
Octavian Damiean
It's localized. There is not any other solution for this? I managed to do it with a 9 patch but having problems when changing locale.