admin管理员组

文章数量:1023056

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?

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?

本文标签: javaHow to align text at top edge of canvas using StaticLayoutStack Overflow