2

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!

momoja
  • 938
  • 9
  • 23
  • Hi A.A, i updated my post, although there's really not much code to post. my implementation is your run-of-the-mill setCompoundDrawables to a TextView. – momoja Apr 22 '14 at 14:17

2 Answers2

1

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.

Aksiom
  • 1,565
  • 4
  • 25
  • 39
  • Hi Aksiom, I realize that, altho I wouldn't want to create a relative layout with a text and an image. I'm trying to find a way to make the drawableLeft work. But thank you for you suggestion. Maybe if I dont think of a good solution, I'll just revert to this one. Thank you – momoja Apr 22 '14 at 14:19
0

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.

Community
  • 1
  • 1
Reinier
  • 3,836
  • 1
  • 27
  • 28