HarmonyOS swiper指示器位置修改?

在项目中,因为需要轮播图功能,使用的swiper组件,因指示器距离下边距过高,无法与其他系统保持统一,要如何设置距离底边距离

阅读 460
1 个回答

可以参考:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-swiper-V5\#indicator

在设置indicator为负数时,可以给循环内部容器设置padding或margin,让indicator看起来像在内容区域外部

@Entry
@Component
struct Index {
  imgArr: ResourceStr[] = [$r('app.media.background'), $r('app.media.startIcon'), $r('app.media.app_icon')]

  build() {
    Row() {
      Swiper() {
        ForEach(this.imgArr, (item: ResourceStr, index: number) => {
          Stack() {
            Text(`${index}`).zIndex(1).fontSize(36)
            Image(item).width('100%').height('100%')
          }
          .margin({ bottom: 36 })
        }, (item: ResourceStr, index: number) => `${index}`)
      }
      .indicator(
        // 设置圆点导航点样式
        new DotIndicator().itemWidth(15)
          .itemHeight(15)
          .selectedItemWidth(15)
          .selectedItemHeight(15)
          .color(Color.Gray)
          .selectedColor(Color.Blue)
          .bottom(0)).width('100%').height(300)
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进