美文网首页初见
Canvas.clipRect():一个Textview 两种颜

Canvas.clipRect():一个Textview 两种颜

作者: 中路杀神ai | 来源:发表于2020-04-18 13:01 被阅读0次

private fun drawTexts(canvas: Canvas, paint: Paint, start: Int, end: Int) {
canvas.save()

    val clipRect = Rect(start, 0, end, height)
    canvas.clipRect(clipRect)
    name = text.toString()
    val rect = Rect()
    paint.getTextBounds(name, 0, name.length, rect)
    val x = width / 2 - rect.width() / 2.toFloat()
    val fontMetricsInt = _changePaint.fontMetricsInt
    val dy = (fontMetricsInt.bottom - fontMetricsInt.top) / 2 - fontMetricsInt.bottom
    val y = height / 2 + dy.toFloat()
    canvas.drawText(name, x, y, paint)
    canvas.restore()
}

相关文章

网友评论

    本文标题:Canvas.clipRect():一个Textview 两种颜

    本文链接:https://www.haomeiwen.com/subject/rfpvvhtx.html