Question

I have a textView in which I put some text (obviously) and a Drawable left. Unfortunately, when I use phones with small screens like a Samsung Galaxy Y, instead of just a single line, the text runs over to a second line. (which is fine). However, the drawable that I set now aligns itself to the center of the textview, and not on the left of the first line.

I want my drawable to stay aligned to the first line of text in my textview, no matter how many lines of text, my textview holds. Is there a way to do this? Can anyone point me in the right direction?

my implementation is pretty straightforward

...
tv.setCompoundDrawables(drawableLeft, null, null, null);

where my drawableLeft is the image from my drawable folder.

Thanks a lot!

Was it helpful?

Solution

Try to use a drawable like a separate view (ie ImageView) and not to set it as a tag in a TextView. Using that will grant you more control over the drawable/ImageView it self.

OTHER TIPS

In order to align a Drawable to the top of your TextView you can use a custom Drawable that wraps the Drawable you want to show. Then, override the method onDraw(Canvas) in your custom Drawable and translate the Canvas to manipulate the position of your Drawable.

See my answer here for an example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top