setCompoundDrawablePadding - How to Add Padding to a Drawable in a TextView, using Java
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:drawableBottom, android:drawableEnd, android:drawableLeft, android:drawableRight.
(This example will use android:drawableLeft)
Examples include:
android:drawableBottom, android:drawableEnd, android: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:
Related Articles: