Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:drawableLeft margin and/or padding

Is it possible to set the margin or padding for the image which we added with the android:drawableLeft?

like image 755
androidNewbies Avatar asked Jul 26 '10 17:07

androidNewbies


2 Answers

As cephus mentioned android:drawablePadding will only force padding between the text and the drawable if the button is small enough.

When laying out larger buttons you can use android:drawablePadding in conjunction with android:paddingLeft and android:paddingRight to force the text and drawable inward towards the center of the button. By adjusting the left and right padding separately you can make very detailed adjustments to the layout.

Here's an example button that uses padding to push the text and icon closer together than they would be by default:

<Button android:text="@string/button_label"      android:id="@+id/buttonId"     android:layout_width="160dip"     android:layout_height="60dip"     android:layout_gravity="center"     android:textSize="13dip"     android:drawableLeft="@drawable/button_icon"     android:drawablePadding="2dip"     android:paddingLeft="30dip"     android:paddingRight="26dip"     android:singleLine="true"     android:gravity="center" />   
like image 91
Jordan Avatar answered Oct 11 '22 13:10

Jordan


TextView has an android:drawablePadding property which should do the trick:

android:drawablePadding

The padding between the drawables and the text.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol drawablePadding.

like image 43
Cheryl Simon Avatar answered Oct 11 '22 14:10

Cheryl Simon