HarmonyOS Slider组件中showTips气泡宽度太小,无法显示需要的文案

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

参考自定义slider自带的tips样式:

const BLOCK_DEFAULT_BORDER_WIDTH = 4;

@Entry
@Component
struct SliderIndex {
  @State isTipShow: boolean = false;
  @State tipsOffset: number = 0;
  private slideHeight: number = 300;
  private blockSize: number = 20;
  private tipHeight: number = 40;
  private hideTipTask?: number;

  private showTip(value: number) {
    this.isTipShow = true
    let percent = Number((value / 100).toFixed(2));
    this.tipsOffset = (this.slideHeight - this.blockSize - BLOCK_DEFAULT_BORDER_WIDTH * 2) * percent -
      (this.tipHeight / 2 - (this.blockSize / 2 + BLOCK_DEFAULT_BORDER_WIDTH));
  }

  private hideTip() {
    clearTimeout(this.hideTipTask)
    this.hideTipTask = setTimeout(() => {
      this.isTipShow = false
    }, 3000)
  }

  build() {
    Row() {
      Slider({ direction: Axis.Vertical, })
        .height(this.slideHeight)
        .selectedColor(Color.Green)
        .trackColor('#5a5a5a')
        .trackThickness(10)
        .blockSize({ width: this.blockSize, height: this.blockSize })
        .selectedColor('#FF6103')
        .onChange((value: number, mode: SliderChangeMode) => {
          switch (mode) {
            case SliderChangeMode.Moving:
            case SliderChangeMode.Click:
              this.showTip(value);
              break;
            case SliderChangeMode.End:
              this.hideTip();
              break;
          }
        })
      if (this.isTipShow) {
        Text("i am tip!")
          .fontSize(12)
          .height(this.tipHeight)
          .offset({ y: this.tipsOffset })
          .fontColor(Color.White)
          .backgroundColor("#66000000")
          .padding(10)
          .borderRadius(5)
          .hitTestBehavior(HitTestMode.Transparent)
      }
    }
    .alignItems(VerticalAlign.Top)
    .padding(20)
    .height('100%')
    .width('100%')
  }
}
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS Slider组件气泡提示显示不全
39浏览 • 1回复 待解决
HarmonyOS Slider showTips
305浏览 • 1回复 待解决
HarmonyOS 双向滑动Slider组件
47浏览 • 1回复 待解决
HarmonyOS Slider无法自定义滑轨样式
24浏览 • 1回复 待解决
HarmonyOS Picker文案如何自定义
36浏览 • 1回复 待解决
HarmonyOS ActionSheet选项间距太小
32浏览 • 1回复 待解决
HarmonyOS 跨module调用组件无法显示
345浏览 • 1回复 待解决
气泡组件有推荐实现方式么?
449浏览 • 1回复 待解决