HarmonyOS Swiper指示器显示错误

属性上已经设置不显示指示器了,UI上还是展示了出来。

Swiper(this.controller){ 
  ForEach(this.titles, (subData: string, currentIndex: number) => { 
    MarketStockListItem({item: subData, currentIndex: currentIndex}) 
  }) 
} 
.onChange((index: number) => { 
  this.currentIndex = index; 
}) 
.width('100%') 
.displayCount(1, true) 
.index($$this.currentIndex) 
.autoPlay(false) 
.indicator(false) 
.cachedCount(6) 
.loop(false)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
HarmonyOS
2024-11-26 10:31:04
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

​可以使用indicator设置颜色透明,让它不显示。详细内容请参见:​https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-swiper-V5

.indicator(Indicator.dot() 
  .itemWidth(15) 
  .itemHeight(15) 
  .selectedItemWidth(15) 
  .selectedItemHeight(15) 
  .color('#00000000') 
  .selectedColor('#00000000'))
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

设置透明是替换方案,单独设置indicator也是可以生效的,参考demo:

// xxx.ets 
class MyDataSource implements IDataSource { 
  private list: number[] = [] 
 
  constructor(list: number[]) { 
    this.list = list 
  } 
 
  totalCount(): number { 
    return this.list.length 
  } 
 
  getData(index: number): number { 
    return this.list[index] 
  } 
 
  registerDataChangeListener(listener: DataChangeListener): void { 
  } 
 
  unregisterDataChangeListener() { 
  } 
} 
 
@Entry 
@Component 
struct SwiperExample { 
  private swiperController: SwiperController = new SwiperController() 
  private data: MyDataSource = new MyDataSource([]) 
 
  aboutToAppear(): void { 
    let list: number[] = [] 
    for (let i = 1; i <= 10; i++) { 
      list.push(i); 
    } 
    this.data = new MyDataSource(list) 
  } 
 
  build() { 
    Column({ space: 5 }) { 
      Swiper(this.swiperController) { 
        LazyForEach(this.data, (item: string) => { 
          Text(item.toString()) 
            .width('90%') 
            .height(160) 
            .backgroundColor(0xAFEEEE) 
            .textAlign(TextAlign.Center) 
            .fontSize(30) 
        }, (item: string) => item) 
      } 
      .cachedCount(2) 
      .index(1) 
      .autoPlay(true) 
      .interval(4000) 
      .loop(true) 
      .duration(1000) 
      .itemSpace(0) 
      // .indicator( // 设置圆点导航点样式 
      //   new DotIndicator() 
      //     .itemWidth(15) 
      //     .itemHeight(15) 
      //     .selectedItemWidth(15) 
      //     .selectedItemHeight(15) 
      //     .color(Color.Gray) 
      //     .selectedColor(Color.Blue)) 
      .indicator(false) 
      // .loop(false) 
      // .indicator(Indicator.dot() 
      //   .itemWidth(15) 
      //   .itemHeight(15) 
      //   .selectedItemWidth(15) 
      //   .selectedItemHeight(15) 
      //   .color('#00000000') 
      //   .selectedColor('#00000000')) 
      .displayArrow({ // 设置导航点箭头样式 
        showBackground: true, 
        isSidebarMiddle: true, 
        backgroundSize: 24, 
        backgroundColor: Color.White, 
        arrowSize: 18, 
        arrowColor: Color.Blue 
      }, false) 
      .curve(Curve.Linear) 
      .onChange((index: number) => { 
        console.info(index.toString()) 
      }) 
      .onGestureSwipe((index: number, extraInfo: SwiperAnimationEvent) => { 
        console.info("index: " + index) 
        console.info("current offset: " + extraInfo.currentOffset) 
      }) 
      .onAnimationStart((index: number, targetIndex: number, extraInfo: SwiperAnimationEvent) => { 
        console.info("index: " + index) 
        console.info("targetIndex: " + targetIndex) 
        console.info("current offset: " + extraInfo.currentOffset) 
        console.info("target offset: " + extraInfo.targetOffset) 
        console.info("velocity: " + extraInfo.velocity) 
      }) 
      .onAnimationEnd((index: number, extraInfo: SwiperAnimationEvent) => { 
        console.info("index: " + index) 
        console.info("current offset: " + extraInfo.currentOffset) 
      }) 
 
      Row({ space: 12 }) { 
        Button('showNext') 
          .onClick(() => { 
            this.swiperController.showNext() 
          }) 
        Button('showPrevious') 
          .onClick(() => { 
            this.swiperController.showPrevious() 
          }) 
      }.margin(5) 
    }.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.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
分享
微博
QQ
微信
回复
2024-11-26 15:18:37
相关问题
HarmonyOS Swiper指示器
698浏览 • 0回复 待解决
如何设置swiper指示器显示
1551浏览 • 1回复 待解决
HarmonyOS Swiper指示器
643浏览 • 1回复 待解决
HarmonyOS 关于Swiper指示器问题
1152浏览 • 1回复 待解决
HarmonyOS swiper修改指示器问题
556浏览 • 1回复 待解决
HarmonyOS如何自定义Swiper指示器样式?
712浏览 • 0回复 待解决
HarmonyOS 偶现app图标显示错误
904浏览 • 1回复 待解决