HarmonyOS Gauge组件使用问题

Gauge如何实现手动滑动效果,动态更新Gauge的value值?

HarmonyOS
2024-12-24 15:52:39
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

Gauge目前不支持手动滑动相关,下面是结合按钮实现的动态更新Gauge的value值的demo:

//该示例实现了Gauge组件使用Builder定制内容区,使用了环形图表组件,按钮和文本框。点击增加按钮,环形图表指针位置会向右偏移,反之点减少按钮环形图表指针位置会向左偏移。
@Builder
function buildGauge(config: GaugeConfiguration) {
  Column({ space: 30 }) {
    Row() {
      Text('【ContentModifier】 value:' + JSON.stringify((config.contentModifier as MyGaugeStyle).value) +
        '  min:' + JSON.stringify((config.contentModifier as MyGaugeStyle).min) +
        '  max:' + JSON.stringify((config.contentModifier as MyGaugeStyle).max))
        .fontSize(12)
    }

    Text('【Config】value:' + config.value + '  min:' + config.min + '  max:' + config.max).fontSize(12)
    Gauge({
      value: config.value,
      min: config.min,
      max: config.max
    }).width("50%")
  }
  .width("100%")
  .padding(20)
  .margin({ top: 5 })
  .alignItems(HorizontalAlign.Center)
}

class MyGaugeStyle implements ContentModifier<GaugeConfiguration> {
  value: number = 0
  min: number = 0
  max: number = 0

  constructor(value: number, min: number, max: number) {
    this.value = value
    this.min = min
    this.max = max
  }

  applyContent(): WrappedBuilder<[GaugeConfiguration]> {
    return wrapBuilder(buildGauge)
  }
}

@Entry
@Component
struct refreshExample {
  @State gaugeValue: number = 10
  @State gaugeMin: number = 0
  @State gaugeMax: number = 100

  build() {
    Column({ space: 20 }) {
      Gauge({
        value: this.gaugeValue,
        min: this.gaugeMin,
        max: this.gaugeMax,
      })
        .contentModifier(new MyGaugeStyle(30, 10, 100))

      Column({ space: 20 }) {
        Row({ space: 20 }) {
          Button('增加').onClick(() => {
            if (this.gaugeValue < this.gaugeMax) {
              this.gaugeValue += 1
            }
          })
          Button('减少').onClick(() => {
            if (this.gaugeValue > this.gaugeMin) {
              this.gaugeValue -= 1
            }
          })
        }
      }.width('100%')
    }.width('100%').margin({ top: 5 })
  }
}
  • 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.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
分享
微博
QQ
微信
回复
2024-12-24 18:16:52
相关问题
Gauge组件问题,该如何解决?
1222浏览 • 1回复 待解决
HarmonyOS UI组件使用问题
819浏览 • 1回复 待解决
HarmonyOS Refresh组件使用问题
787浏览 • 1回复 待解决
HarmonyOS 使用Video组件问题
1045浏览 • 1回复 待解决
HarmonyOS Scroll组件使用问题
1160浏览 • 1回复 待解决
HarmonyOS Navigation组件使用问题
728浏览 • 1回复 待解决
HarmonyOS swiper组件使用问题
1090浏览 • 1回复 待解决
HarmonyOS LazyForEach组件dataSource使用问题
1581浏览 • 2回复 待解决
HarmonyOS 组件.bindPopup属性使用问题
1063浏览 • 1回复 待解决
Marquee组件使用问题有哪些?
1126浏览 • 0回复 待解决
HarmonyOS Web组件和List的嵌套使用问题
1306浏览 • 1回复 待解决
OpenHarmony 使用WEB组件传值问题
4547浏览 • 1回复 待解决
HarmonyOS Tabs组件组件问题
1380浏览 • 1回复 待解决
HarmonyOS 组件封装问题
759浏览 • 1回复 待解决
HarmonyOS 组件选择问题
662浏览 • 1回复 待解决