Reputation: 938
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!
Upvotes: 2
Views: 3338
Reputation: 3876
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.
Upvotes: 0
Reputation: 1585
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.
Upvotes: 1