文章目录前言一、Divider 基础用法1.1 最简单的水平分隔线1.2 本项目中的 Divider二、Divider 完整属性2.1 竖向分隔线2.2 Divider 属性汇总三、List 内置分隔线3.1 List 的 divider 属性3.2 手动 Divider vs List divider 对比四、其他视觉分隔方式4.1 间距分隔space4.2 背景色分隔4.3 圆角卡片分组现代风格五、视觉分隔设计规范5.1 HarmonyOS 分隔线设计原则5.2 深色模式适配总结前言在 UI 设计中视觉分隔承担着组织信息层次、引导用户视线的重要职责。一条 1px 的分隔线能让复杂的界面瞬间清晰有序。HarmonyOS ArkUI 提供了Divider组件和多种视觉分隔方案本篇系统讲解所有分隔方式并结合本项目源码展示最佳实践。一、Divider 基础用法1.1 最简单的水平分隔线EntryComponentstruct DividerBasicDemo{build(){Column({space:0}){Text(第一项).padding(16).width(100%)Divider()// ← 最基础的分隔线.strokeWidth(1)// 线宽逻辑像素.color(#E8E8E8)// 线条颜色Text(第二项).padding(16).width(100%)Divider().strokeWidth(0.5)// 0.5px 更细腻.color(#F0F0F0)Text(第三项).padding(16).width(100%)}.width(100%).backgroundColor(#FFFFFF).borderRadius(12).margin(16)}}1.2 本项目中的 DividerGasStationPage.ets的stationInfoCard中Divider().strokeWidth(Constants.STROKE_WIDTH)// 细线.color($r(sys.color.mask_fourth))// 使用系统颜色自动适配深色模式.width(Constants.PERCENT_70)// 只占70%宽度左对齐不顶边设计解析width(70%)而不是100%产生内缩感符合 Material/HarmonyOS 设计语言使用sys.color.mask_fourth系统颜色自动适配深色模式深色下变为深色线二、Divider 完整属性2.1 竖向分隔线EntryComponentstruct VerticalDividerDemo{build(){Row(){Column(){Text(⛽).fontSize(32)Text(加油).fontSize(12).fontColor(#999999)}.padding({left:24,right:24,top:16,bottom:16})// 竖向分隔线Divider().vertical(true)// ← 竖向.strokeWidth(1).color(#E8E8E8).height(40)// 需要设置高度Column(){Text().fontSize(32)Text(维修).fontSize(12).fontColor(#999999)}.padding({left:24,right:24,top:16,bottom:16})Divider().vertical(true).strokeWidth(1).color(#E8E8E8).height(40)Column(){Text().fontSize(32)Text(便利).fontSize(12).fontColor(#999999)}.padding({left:24,right:24,top:16,bottom:16})}.width(100%).backgroundColor(#FFFFFF).borderRadius(12).margin(16).justifyContent(FlexAlign.Center)}}2.2 Divider 属性汇总属性类型说明strokeWidthnumber线条粗细单位 vpcolorResourceColor线条颜色verticalbooleantrue竖向false横向默认lineCapLineCapStyle线端样式Butt/Round/Square.width()number|string水平线长度.height()number|string竖向线高度.margin()边距对象分隔线两侧间距三、List 内置分隔线3.1 List 的 divider 属性比手动插入 Divider 更便捷List 自带分隔线属性EntryComponentstruct ListDividerDemo{privatestations:string[][望京石化,朝阳石油,国贸壳牌,三里屯BP,东直门Shell];build(){Column({space:16}){Text(List 内置分隔线).fontSize(18).fontWeight(FontWeight.Bold)List(){ForEach(this.stations,(station:string){ListItem(){Text(station).padding({left:16,right:16,top:14,bottom:14}).fontSize(15).width(100%)}})}.divider({strokeWidth:0.5,color:#F0F0F0,startMargin:16,// 左侧缩进不顶边endMargin:0,// 右侧不缩进}).backgroundColor(#FFFFFF).borderRadius(12).margin({left:16,right:16})}.padding({top:24}).width(100%)}}3.2 手动 Divider vs List divider 对比方式优点缺点Listdivider属性代码简洁自动处理最后一项样式控制有限手动在 ListItem 中加 Divider完全自定义位置、颜色、宽度需要处理最后一项不显示// 手动分隔线处理最后一项List(){ForEach(this.stations,(station:string,index:number){ListItem(){Column(){Text(station).padding(16).width(100%)// 最后一项不显示分隔线if(indexthis.stations.length-1){Divider().strokeWidth(0.5).color(#F0F0F0).margin({left:16})}}}})}四、其他视觉分隔方式4.1 间距分隔space最简单的分隔用 Row/Column 的space属性Column({space:16}){// 子组件之间自动16vp间距// ...}4.2 背景色分隔用不同背景色区分区域比线条更柔和EntryComponentstruct BackgroundDividerDemo{build(){Column({space:0}){// 分组标题灰色背景充当分隔Text(位置服务).fontSize(13).fontColor(#999999).padding({left:16,top:16,bottom:8}).width(100%).backgroundColor(#F5F7FA)// ← 背景色分隔// 内容区白色背景Column(){Text(精确定位).padding(16).width(100%).backgroundColor(#FFFFFF)Divider().strokeWidth(0.5).color(#F0F0F0).margin({left:16})Text(模糊定位).padding(16).width(100%).backgroundColor(#FFFFFF)}// 分组标题Text(通知设置).fontSize(13).fontColor(#999999).padding({left:16,top:16,bottom:8}).width(100%).backgroundColor(#F5F7FA)// 内容区Text(推送通知).padding(16).width(100%).backgroundColor(#FFFFFF)}.width(100%)}}4.3 圆角卡片分组现代风格EntryComponentstruct CardGroupDemo{build(){Column({space:16}){// 卡片1定位设置Column({space:0}){Text(定位权限).padding({left:16,right:16,top:14,bottom:14}).fontSize(16).width(100%)Divider().strokeWidth(0.5).color(#F0F0F0).margin({left:16})Text(地图显示).padding({left:16,right:16,top:14,bottom:14}).fontSize(16).width(100%)}.backgroundColor(#FFFFFF).borderRadius(12).shadow({radius:2,color:#10000000,offsetX:0,offsetY:1}).margin({left:16,right:16})// 卡片2通知设置Column({space:0}){Text(推送通知).padding({left:16,right:16,top:14,bottom:14}).fontSize(16).width(100%)}.backgroundColor(#FFFFFF).borderRadius(12).shadow({radius:2,color:#10000000,offsetX:0,offsetY:1}).margin({left:16,right:16})}.padding({top:24}).width(100%).backgroundColor(#F5F7FA)}}五、视觉分隔设计规范5.1 HarmonyOS 分隔线设计原则场景推荐方式参数建议列表项间Divider / List dividerstrokeWidth: 0.5左缩进16vp卡片内区块DividerstrokeWidth: 0.570-90%宽功能分组背景色切换#F5F7FA / #FFFFFF 交替重要分隔较厚线条strokeWidth: 1~2装饰性间距space: 12~165.2 深色模式适配// ❌ 不推荐硬编码颜色深色模式下不适配Divider().color(#E8E8E8)// ✅ 推荐使用系统颜色资源Divider().color($r(sys.color.mask_fourth))// ✅ 或使用 app 资源在 color.json 中同时定义浅色/深色Divider().color($r(app.color.divider_color))总结Divider 是 ArkUI 中最小却最实用的组件之一。水平线用于分隔列表项竖线用于分隔并列内容配合 List 的divider属性可以快速实现标准列表分隔。在现代 App 设计中结合卡片圆角、背景色切换和间距比纯粹的线条分隔能实现更精致的层次感。始终使用系统颜色资源而非硬编码颜色值以确保深色模式的正确适配。