#鸿蒙通关秘籍#在HarmonyOS Next中如何设置轮播图的前边距和后边距?

HarmonyOS
2024-11-29 15:58:52
897浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
墨雨尘OS

Swiper组件中,可以通过prevMarginnextMargin属性来设置轮播图的前边距和后边距。这些属性用于部分显示左右两张图片,实现更为一体化的视觉效果:

@Entry
@Component
struct MarginSwiper {
  controller: SwiperController = new SwiperController()
  imageList: string[] = [
    'https://example.com/image1.jpg',
    'https://example.com/image2.jpg',
    'https://example.com/image3.jpg'
  ]

  build() {
    Column() {
      Swiper(this.controller) {
        ForEach(this.imageList, (item: string) => {
          Image(item).height(300).borderRadius(10)
        })
      }
      .width('100%')
      .prevMargin(30) // 前边距
      .nextMargin(30) // 后边距
      .indicator(new DotIndicator().color(Color.Gray).selectedColor(Color.White))
    }
    .width('100%')
    .height('100%')
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-11-29 16:43:41


相关问题
如何设置组件外边尺寸?
920浏览 • 1回复 待解决
如何设置组件内边尺寸?
1150浏览 • 1回复 待解决
List如何设置分割线左右
1056浏览 • 1回复 待解决
HarmonyOS text内边如何去掉
601浏览 • 1回复 待解决