如何使用drawTextOnPath旋转在直线上绘制的文本(无半径)?

问题描述 投票:1回答:1

我想旋转画布中的数字,

这是我尝试过的:

override fun onDraw(canvas: Canvas) {    
var i = 0
while (i < rulerHeightInInch) {
val markingPositionYaxis =
            screenHeightInPx - (ydpinch * i + topThreshold)
paint.textSize = getPixelValueForDp(18.0f)
                    val path = Path()
                    path.reset()
                    path.moveTo(
                        (getPixelValueForDp(30f) + paint.textSize),
                        markingPositionYaxis +17
                    )
                    path.lineTo(
                        (getPixelValueForDp(30f) + paint.textSize),
                        markingPositionYaxis - (paint.textSize)
                    )
                    canvas.drawTextOnPath(nf.format(i / 32), path, 0f, 0f, paint)
}
i++
}
}

第一张图片就是我现在拥有的

This is what I have in portrait mode from top left to bottom left:

第二张图片就是我想要的This is what I want

我不想绘制圆形路径,也不想使用想要从上到下的直线半径

android android-canvas android-custom-view
1个回答
0
投票

这是我的做法:

canvas.save()
canvas.rotate(180f,(getPixelValueForDp(30f) + paint.textSize),markingPositionYaxis)
canvas.drawTextOnPath(nf.format(i / 32), path, 0f, 0f, paint)
canvas.restore()
© www.soinside.com 2019 - 2024. All rights reserved.