@Entry
@Component
struct PolylineExample {
@State points:Array<Array<number>> = [[0,150], [75,100], [150,150],[225,200],[300,300]]
build() {
Column({ space: 10 }) {
// 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(20,60),到达终点(100, 100)
Stack(){
Polyline({ width: 300, height: 300 })
.points(this.points)
.fillOpacity(0)
.stroke(Color.Blue)
.strokeWidth(3)
Circle({ width: 6, height: 6 }).position({x:297,y:147})
}
.borderWidth(2).margin(50)
}.width('100%')
}
}
Stack组件设置的
.margin(50)
导致Polyline组件大小被挤压,去掉margin(50)设置显示正常。