0

I need use TextView with outline text. I try use it: https://stackoverflow.com/a/10294290/4181010 , but it doesn't work correctly with android:layout_width="wrap_content", because it doesn't increase canvas when add outlines.

enter image description here

I need to increase the canvas to include the value of strokeWidth.

I suggest I have to override onMeasure somehow, but TextView call final method setMeasuredDimension at the end of onMeasure to apply view size and I can not intervene at this point so as not to have to rewrite the whole method.

Scaling the canvas in OnDraw does not work either, because TextView scales draw text with canvas.

My solution is increase canvas and use canvas.translate() to move in right position before draw text.
And my question: How can I increase the size of the canvas with minimal intervention? Or someone know another solution for this problem?

Community
  • 1
  • 1
inverse12
  • 186
  • 1
  • 7

1 Answers1

0

I'm guessing you are drawing the text twice, once with the orange (manually on the canvas) and once with the white (what the TextView is drawing with super.onDraw).

Instead of drawing the larger orange manually, you could instead draw the smaller white text and leave the orange text to TextView's super.onDraw. That way everything should fit within the canvas.

Alex Yau
  • 101
  • 3
  • unfortunatly i cann't use small font size for text and big font size for outline orange. It works for only one character. because interalphabetic space tied to the font size will change with it. – inverse12 Feb 13 '15 at 08:22
  • Have you tried this [solution](http://stackoverflow.com/a/3865861/4191579)? It explain you should draw the text with stroke the first time, and add padding to the TextView so the stroke does not get cut off. – Alex Yau Feb 13 '15 at 16:18