How to align text with its composite drawings in TextView?

I cannot figure out how to set the alignment of the text and its composite drawing (less text) in the TextView. The default alignment seems to be the center, but I need to align them around the edge.

PS: android:gravity works great if the composite drawing is more text but no less.

+6
source share
2 answers

It looks like you are using a fixed-size image for android:drawableLeft .

Try using nine-patch or determining whether you can migrate through an XML resource file. This way your stretch sizes will stretch to align what you want in the TextView .

+1
source

I had a similar problem in that I wanted to use setCompoundDrawables to set the top drawable for the floating tooltip, however TextView (EditText) sets the top drawable to the center, regardless of its width.

I use custom Drawable and inside his draw method, I grab clipBounds and translate it on top, left to return to TextView position 0,0.

Another way to do this is easy: getMatrix and mapPoints from 0.0, then take a negative result from them and translate 0.0 back there.

0
source

All Articles