开发者

How to position StaticLayout in android?

开发者 https://www.devze.com 2022-12-31 19:36 出处:网络
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

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....


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号