HarmonyOS CustomBuilder加载慢

//背景,实现类似于.9图
@Builder
BubbleBackground() {
  Image($r('app.media.bg_made'))
    .objectFit(ImageFit.Fill)
    .resizable({
      slice: {
        left: px2vp(40),
        right: px2vp(40),
        top: px2vp(40),
        bottom: 1,
      }
    })

    .width("100%")
    .height("100%")
}


Stack({ alignContent: Alignment.Bottom }).background(this.BubbleBackground())

加载总是慢一步,有时候还会出现加载不出来

HarmonyOS
2024-12-24 15:45:21
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

自定义背景渲染会有一定延迟,不能响应事件,不能进行动态更新。该属性不支持嵌套使用,且不支持预览器预览。官方文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-background-V5#background10

可以通过通用属性borderImage实现,请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-border-image-V5

示例参考如下:

// xxx.ets
@Entry
@Component
struct BorderImage {
  @State WidthValue: number = 0
  @State SliceValue: number = 0
  @State OutSetValue: number = 0
  @State RepeatValue: RepeatMode[] = [RepeatMode.Repeat, RepeatMode.Stretch, RepeatMode.Round, RepeatMode.Space]
  @State SelectIndex: number = 0
  @State SelectText: string = 'Repeat'
  @State FillValue: boolean = false
  build() {
    Row() {
      Column({ space: 20 }) {
        Row() {
          Text('This is borderImage.').textAlign(TextAlign.Center).fontSize(50)
        }
        .borderImage({
          source: $r('app.media.app_icon'),
          slice: this.SliceValue,
          width: this.WidthValue,
          outset: this.OutSetValue,
          repeat: this.RepeatValue[this.SelectIndex],
          fill: this.FillValue
        })

        Column() {
          Text(`borderImageSlice = ${this.SliceValue}px`)
          Slider({
            value: this.SliceValue,
            min: 0,
            max: 100,
            style: SliderStyle.OutSet
          })
            .onChange((value: number, mode: SliderChangeMode) => {
              this.SliceValue = value
            })
        }

        Column() {
          Text(`borderImageWidth = ${this.WidthValue}px`)
          Slider({
            value: this.WidthValue,
            min: 0,
            max: 100,
            style: SliderStyle.OutSet
          })
            .onChange((value: number, mode: SliderChangeMode) => {
              this.WidthValue = value
            })
        }

        Column() {
          Text(`borderImageOutSet = ${this.OutSetValue}px`)
          Slider({
            value: this.OutSetValue,
            min: 0,
            max: 100,
            style: SliderStyle.OutSet
          })
            .onChange((value: number, mode: SliderChangeMode) => {
              this.OutSetValue = value
            })
        }

        Row() {
          Text('borderImageRepeat: ')
          Select([{ value: 'Repeat' }, { value: 'Stretch' }, { value: 'Round' }, { value: 'Space' }])
            .value(this.SelectText)
            .selected(this.SelectIndex)
            .onSelect((index: number, value?: string) => {
              this.SelectIndex = index
              this.SelectText = value as string
            })
        }

        Row() {
          Text(`borderImageFill: ${this.FillValue} `)
          Toggle({ type: ToggleType.Switch, isOn: this.FillValue })
            .onChange((isOn: boolean) => {
              this.FillValue = isOn
            })
        }

      }
      .width('100%')
    }
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-24 18:34:32
相关问题
HarmonyOS Web加载如何调优
160浏览 • 1回复 待解决
HarmonyOS web控件加载url速度
113浏览 • 1回复 待解决
冷启动加载问题定位三板斧
1296浏览 • 1回复 待解决
什么是PolarDB MySQLSQL?
3788浏览 • 1回复 待解决
发个原创审核这么
4507浏览 • 1回复 已解决
HarmonyOS 路由切换页面过渡问题
662浏览 • 1回复 待解决
PolarDB修改表数据怎么回事?
3406浏览 • 1回复 待解决
在@watch中使用异步方法后UI反应
659浏览 • 1回复 待解决
关于启动问题首帧卡顿分析
712浏览 • 1回复 待解决
MySQL的数据查询的问题怎么解决?
2172浏览 • 1回复 待解决