Swiper组件(提供滑动轮播显示的能力)

174 阅读1分钟

1.Swiper 可以内含多个子组件是容器,scroll(滚动)包含单个子组件 2.Swiper尺寸优先级高内容高于内容。当Swiper有设置尺寸时,内容不管有无设置尺寸都会与Swiper尺寸一致;当Swiper没有设置尺寸时内容就是自身尺寸

@Entry
@Component
struct Index1 {
  build() {
    Column() {
     Swiper(){
       Column(){}
       .width(100000000000000000)
       .height(10000000000000000000)
       .backgroundColor(Color.Red)
       Column(){}
       .width(200)
       .height(200)
       .backgroundColor(Color.Orange)
       Column(){}
       .width(200)
       .height(100)
       .backgroundColor(Color.Yellow)
     }
     .width(300)
     .height(300)

    }
    .height('100%')
    .width('100%')
    .backgroundColor(Color.Green)
  }
}
image.png

属性

  1. 是否循环loop
  2. 是否自动播放autoplay
  3. 轮播间隔intreval
  4. 方向是否为纵向(默认fales)
.loop(false) // 是否开启循环 true/false
      .autoPlay(true) // 是否自动播放 true/false
      .interval(4000) // 自动播放时间间隔 单位毫秒
      .vertical(true) // 是否纵向滑动

调整导航点indicator

Swiper(){}
  .indicator(
    Indicator.dot()  
  ) 

导航点内

.indicator(
        Indicator.dot()
          .left(10)// 左侧距离
          .top(10)// 顶部距离
          .bottom(10)// 底部距离
          .right(10)// 右侧距离(距离属性组合使用,无需全部设置)
          .itemWidth(20)// 指示器宽度
          .itemHeight(20)// 指示器高度
          .selectedItemWidth(30)// 选中指示器宽度
          .selectedItemHeight(30)// 选中指示器高度
          .selectedColor(Color.Yellow)// 选中指示器颜色
          .color(Color.Blue) // 默认指示器宽度
      ) // 圆形导航点

1.导航点表现方式:圆点和数字

image.png

  1. 导航点位置属性left,right,bottom,top(导航点离Swiper组件的距离)
  2. item+方向,如itemwidth都是设置导航点不支持百分比。
  3. 颜色组件中圆点导航点指示器颜色,selectedColor选中指示器点的颜色