问题
I have one little problem: I am trying go center a given text inside a Canvas with PlayN. I do not have any FontMetrics, because GWT does not offer one, and simple repositioning depending of character number and fontsize just does not works :(..
Can somebody please help
回答1:
Use Graphics.layoutText
to create a TextLayout
.
TextLayout
provides the width and height of the text, which you can use to position it however you like and render it into a Canvas using Canvas.drawText(TextLayout,x,y)
.
来源:https://stackoverflow.com/questions/9211089/textcentering-inside-canvas-playn