setCompoundDrawablePadding - Add Padding to a Drawable in a TextView, using Java

setCompoundDrawablePadding - How to Add Padding to a Drawable in a TextView, using Java

setCompoundDrawablePadding was added in API Level 1
Related XML Attribute: android:drawingPadding

1. Add a drawable named myImage

2. Add the following text to the TextView: "This is an example with a drawable set to the left in a TextView."

3. Add a drawable to the TextView.
    Examples include:
    android:drawableBottomandroid:drawableEndandroid:drawableLeft, android:drawableRight.

 (This example will use android:drawableLeft)


5. Add the code below to the onCreate method.

myTextView.setCompoundDrawablePadding(15dip);

6. Compile and run!



7. You can compare the image above to without android:drawablePadding here, using android:drawableLeft.

Related Articles: