Search code examples
androidtextviewcompound-drawables

How to align the text with its compound drawables in TextView?


I can't figure out how to set the alignment of text and its compound drawable (smaller than text) in a TextView. It seems the default alignment is center, but I need to align them by the edge.

PS: The android:gravity works great if compound drawable is larger than text, but not if smaller.


Solution

  • It sounds like you're using an image with fixed dimensions for android:drawableLeft.

    Try using a nine-patch or defining a drawable through an XML resource file. In this way your drawable's dimensions will stretch to align in the TextView the way that you want it to.