80,362
社区成员
发帖
与我相关
我的任务
分享
var paint = Paint()
override fun onDraw(canvas: Canvas?) {
paint.color = Color.RED
paint.style = Paint.Style.FILL
paint.textSize = 50f
canvas?.drawText("Hello World1",0f,50f,paint)
canvas?.save()
canvas?.rotate(90f,this.measuredWidth/2f,this.measuredHeight/2f)
var x = (this.measuredWidth - this.measuredHeight) /2f
//按中心旋转,绘图应该是长宽互换,且Android绘制文字的基准线,基本以文字底部为准,所以纵向偏移字体高度
var y = (this.measuredHeight - this.measuredWidth) /2f + 50
canvas?.drawText("Hello World2",x,y,paint)
canvas?.restore()
}