Set drawable position inside button

Isaías picture Isaías · Aug 29, 2014 · Viewed 22.8k times · Source

I've got a button and a drawable on the left of the text, but I want the drawable to be closer to the text. So I need to move the drawable.

I've defined android:drawableLeft but the content of the button is not centered.

Here is my code:

<Button
    android:id="@+id/addsubject"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_action_add"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="20dp"
    android:text="@string/addsubject"
    android:textColor="@color/white"
    android:background="@drawable/custombutton1" />

Here is how it looks now:

enter image description here

And here is how I'd like it to be:

enter image description here

Thank you!

Answer

Rakesh Rangani picture Rakesh Rangani · Aug 29, 2014

try this

 <Button
    android:id="@+id/addsubject"
    android:layout_width="160dip"
    android:layout_height="60dip"
    android:layout_gravity="center"
    android:drawableLeft="@drawable/ic_action_add"
    android:drawablePadding="2dip"
    android:gravity="center"
    android:paddingLeft="30dip"
    android:paddingRight="26dip"
    android:singleLine="true"
    android:text="@string/addsubject"
    android:textSize="13dip" />