HarmonyOS Span设置padding和margin不生效,但是imagespan生效

HarmonyOS
2024-12-25 08:31:45
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

span只支持“文本通用属性”,不支持“通用属性”。而height、width、padding、margin 属于通用属性

目前可以使用Text包裹span,然后设置Text的padding、margin 属性。

demo如下:

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

  build() {
    Row() {
      ImageSpan($r('app.media.startIcon'))
        .width(40)
        .margin({ left: 10 })// 这个能生效
        .padding(5) // 这个也能生效

      Text() {
        Span("一个带背景的span,padding不生效")
          .fontColor(Color.Blue)
          .onClick(() => {
            console.log('subspan clicked')
          })
      }
      .padding(20)//
      .margin({ left: 20 })//
      .backgroundColor(Color.Red)
      .borderRadius(30)
    }.width('100%')
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.

ImageSpan的通用属性方法支持尺寸设置、背景设置、边框设置。

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-imagespan-V5#属性

其中尺寸设置包含padding、margin

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-size-V5#padding

span :通用属性方法仅支持文本通用

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-span-V5#属性

文本通用:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-text-style-V5

分享
微博
QQ
微信
回复
2024-12-25 10:33:47


相关问题
HarmonyOS right的paddingmargin生效
1219浏览 • 1回复 待解决
HarmonyOS margin生效
1142浏览 • 1回复 待解决
HarmonyOS margin生效问题
735浏览 • 1回复 待解决
HarmonyOS Span内边距生效
429浏览 • 1回复 待解决
HarmonyOS 宽度100% margin左右生效
620浏览 • 1回复 待解决
HarmonyOS 设置了iconlabel生效
793浏览 • 1回复 待解决
ConstraintSize尺寸设置生效
2870浏览 • 1回复 待解决
HarmonyOS stack设置圆角生效
665浏览 • 1回复 待解决
HarmonyOS Panel 设置 borderRadius 生效
1463浏览 • 1回复 待解决
通过WindowProperties设置属性生效
2590浏览 • 1回复 待解决
HarmonyOS Badge文本颜色设置生效
780浏览 • 1回复 待解决
HarmonyOS Text中的ImageSpanSpan
942浏览 • 1回复 待解决