HarmonyOS 虚线组件?

需求需要在每个list的item添加一条虚线,使用line()添加必须得设置起始点坐标吗?而且坐标必须是固定写死的?如何设置成当前子组件的宽度?或者有没有其他的组件画虚线

阅读 429
1 个回答

line()添加必须得设置起始点坐标,startPoint和endPoint如果不设置或者异常值,则会按默认值处理。可以使用borderWidth修改边框的宽度间接拉开间距,或者使用border属性设置top或者buttom的值来拉开间距。

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Row() {
      Column() {
        Divider()
          .height(0)
            //1.方法1设置borderWidth宽度
            // .borderWidth(2)
            // .borderStyle(BorderStyle.Dashed)
            //2.方法2设置border属性的top或者buttom
          .border({ width: {left:0,right:0,top:0,bottom:2}, color:Color.Black, style: BorderStyle.Dashed })
      }
      .width('100%')
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进