Is it possible to set the margin or padding for the image which we added with the android:drawableLeft
?
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" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With