你必须考虑矩形的偏移量和宽度.
要在外部绘制,您可以使用:
val width = 100f
drawRect(
topLeft = Offset(-width/2, -width/2),
color =Color.Black,
size = Size(size.width + width, size.height + width),
style = Stroke(
width = width
)
)
要在内部绘制,请执行以下操作:
val width = 100f
drawRect(
topLeft = Offset(+ width/2, + width/2),
color =Color.Black,
size = Size(size.width - width, size.height - width),
style = Stroke(
width = width
)
)