初见

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

2020-04-18  本文已影响0人  中路杀神ai

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()
}
上一篇下一篇

猜你喜欢

热点阅读