Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position StaticLayout in android?

I want to created a wrapping text ontop of google maps api. I have been able to do this with a lot of code, but have been working on a better way. My latest attempt is to use the StaticLayout class and the text is wrapping, but I do not know how to position it...no matter what I try it is always starting in the top left corner of the screen....

like image 523
Nick Avatar asked May 25 '10 15:05

Nick


2 Answers

try doing a canvas.translate(x,y) before you call draw(c) on the layout.

like image 198
veelci Avatar answered Sep 23 '22 08:09

veelci


You can do it as follows

//Save canvas before translating it, otherwise restore will cause crash (Underflow in restore - more restores than saves)
canvas.save()

canvas.translate(xPos, yPos);
statictextlayout.draw(canvas);

//After that to reset the canvas back for everything else
canvas.restore();

To continue drawing normally afterwards... call canvas.restore() after you staticlayout draw and you should be good to continue drawing on you canvas.

like image 33
Stevanicus Avatar answered Sep 21 '22 08:09

Stevanicus