Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left/right padding for Button.setCompoundDrawablesWithIntrinsicBounds()?

Tags:

I'm trying to set a left icon on a button with:

setCompoundDrawablesWithIntrinsicBounds(R.drawable.foo, 0, 0, 0); 

but the icon is placed flush up against the left edge of my button, and the text string. Is there a way to specify some left/right padding on the supplied icon so that it isn't right up against the edges?

Thanks

like image 749
user291701 Avatar asked Jun 04 '12 02:06

user291701


1 Answers

I believe what you're looking for is android:drawablePadding

Here's an example of using drawablePadding along with paddingLeft and paddingRight to position an image in a button

<Button     android:id="@+id/button"     android:layout_width="200dp"     android:layout_height="80dp"     android:drawableLeft="@drawable/ic_launcher"     android:drawablePadding="2dip"     android:paddingLeft="30dip"     android:paddingRight="26dip"     android:text="Test" /> 

Image example

like image 146
antew Avatar answered Sep 30 '22 19:09

antew