观察Taotoken平台在多轮对话场景下的token消耗规律
2026/5/7 16:35:40
Path是 HarmonyOS ArkUI 提供的高级自定义绘图组件,支持通过SVG 路径命令绘制任意复杂图形,包括直线、矩形、多边形、曲线、圆弧、心形、不规则图形等。
它是 ArkUI 绘图能力最强大的组件,可实现所有基础绘图组件无法完成的自定义图形。
M/L/Q/C/A/Z/H/V等)width/height才能显示| 属性名 | 作用 | 说明 |
|---|---|---|
| width | 绘制区域宽度 | 必须设置 |
| height | 绘制区域高度 | 必须设置 |
| commands | 路径绘制命令 | SVG 格式字符串,核心属性 |
| fill | 填充颜色 | 内部填充 |
| fillOpacity | 填充透明度 | 0~1 |
| stroke | 描边颜色 | 线条颜色 |
| strokeWidth | 描边宽度 | 线条粗细 |
| strokeDashArray | 虚线样式 | [实线长度, 空白长度] |
| linearGradient | 线性渐变填充 | 渐变颜色 |
| 命令 | 含义 |
|---|---|
| M x y | 移动到起点(Move To) |
| L x y | 画线到点(Line To) |
| H x | 水平画线 |
| V y | 垂直画线 |
| Q x1 y1 x y | 二次贝塞尔曲线 |
| C x1 y1 x2 y2 x y | 三次贝塞尔曲线 |
| A rx ry x-axis-rotation large-arc sweep x y | 椭圆弧 |
| Z | 闭合路径 |
.commands('M0 10 L300 10').commands('M100 0 L0 120 L200 120 Z').commands('M0 0 H200 V100 H0 Z').commands('M0 50 Q150 0 300 50').commands('M0 50 C75 0 150 100 225 50 C300 0 375 100 450 50').commands('M50 60 A80 50 0 1 0 250 60').strokeDashArray([10,5]).commands('M100 30 C140 0 200 40 100 150 C0 40 60 0 100 30 Z')@Entry@Componentstruct PathDemo{build(){Scroll(){Column({space:30}){// 1. 基础直线Text('1. 基础直线').fontSize(14).fontColor('#666')Path().width(300).height(20).commands('M0 10 L300 10').stroke('#409EFF').strokeWidth(3)// 2. 三角形(闭合路径)Text('2. 闭合三角形').fontSize(14).fontColor('#666')Path().width(200).height(120).commands('M100 0 L0 120 L200 120 Z').fill('#67C23A').stroke('#333').strokeWidth(2)// 3. 矩形路径Text('3. 矩形路径').fontSize(14).fontColor('#666')Path().width(200).height(100).commands('M0 0 H200 V100 H0 Z').fillOpacity(0).stroke('#E6A23C').strokeWidth(3)// 4. 二次贝塞尔曲线Text('4. 二次贝塞尔曲线').fontSize(14).fontColor('#666')Path().width(300).height(100).commands('M0 50 Q150 0 300 50').stroke('#F56C6C').strokeWidth(3)// 5. 三次贝塞尔曲线(波浪)Text('5. 三次贝塞尔曲线').fontSize(14).fontColor('#666')Path().width(300).height(100).commands('M0 50 C75 0 150 100 225 50 C300 0 375 100 450 50').stroke('#9B59B6').strokeWidth(3)// 6. 椭圆弧Text('6. 椭圆弧').fontSize(14).fontColor('#666')Path().width(300).height(120).commands('M50 60 A80 50 0 1 0 250 60').stroke('#1ABC9C').strokeWidth(3)// 7. 虚线路径Text('7. 虚线路径').fontSize(14).fontColor('#666')Path().width(300).height(80).commands('M20 40 L280 40').stroke('#FF9800').strokeWidth(2).strokeDashArray([10,5])// 8. 渐变填充心形(复杂路径)Text('8. 渐变填充心形').fontSize(14).fontColor('#666')Path().width(200).height(180).commands('M100 30 C140 0 200 40 100 150 C0 40 60 0 100 30 Z').linearGradient({angle:90,colors:[['#FF5E7C',0.0],['#FF3A5C',1.0]]}).stroke('#fff').strokeWidth(2)}.width('100%').padding(20).backgroundColor('#F5F7FA')}}}运行效果如图:
Z命令可自动闭合路径,形成封闭图形。Path是 ArkUI最强大的绘图组件commands可绘制任何自定义图形如果这篇文章对你有帮助,欢迎点赞、收藏、关注,你的支持是持续创作的动力