I am trying to draw grid of numbers into a canvas.
val textX = x * TILE_SIZE + TILE_SIZE / 2f
val textY = y * TILE_SIZE + TILE_SIZE / 2f
canvas.drawText(number.toString(), textX, textY, textPaint)
This is my paint
private val textPaint: Paint by lazy {
Paint().apply {
isAntiAlias = false
color = Color.WHITE
textSize = TILE_SIZE * 0.1f
textAlign = Paint.Align.CENTER
style = Paint.Style.FILL
}
}
But the canvas keeps disjointing my text and aligns it in a non regular grid. I double checked my position values. Is there something I am missing?
edit: I am aware I have alignment set to CENTER, but if you notice, the text in the 4th row has higher offset then in the previous row
I was able to resolve the text disjointing by adding a subPixelText flag, interestingly, when i set paints flag strikeThroughText
isStrikeThruText = true
I get following result:
This, I believe this shows that the coordinates are set properly but there might be some issue with the paint configuration due to the font size.