java - How to align text at top edge of canvas using StaticLayout? - Stack Overflow

I'm using the StaticLayout.Builder in Android, and have created a text that i want to be at the ed

I'm using the StaticLayout.Builder in Android, and have created a text that i want to be at the edge of the top of the canvas, however i can't seem to get rid of a margin that comes between top of canvas (y=0) and text.

I have tried simply setting y=0, and remove all kind of padding/margin i can find like:

val textPaint = TextPaint().apply { color = Color.RED; textSize = 50f; isAntiAlias = true
    val metrics = fontMetrics
    metrics.ascent = 0f
    metrics.descent = 0f
    metrics.top = 0f
}

And use "setIncludePad(false)" on the builder.

It seems that right, left and bottom don't have the padding/margin, its only on top. I have also drawn a basic "rect" using x=0 and y=0 which aligns at all 4 edges, so the canvas should be correctly set and have its edges on correct places.

Does anyone know why there is a margin over the text when using StaticLayout and setting y=0, and how to get rid of it?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745564966a4633338.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信