Swiper在内部组件高度不一致的情况下,滑动过程中会产生抖动现象。
问题代码示例参考如下:
@Entry @Component struct SwiperTextTest { private swiperController: SwiperController = new SwiperController(); private list: number[] = [0, 1]; build() { RelativeContainer() { Swiper(this.swiperController) { ForEach(this.list, (item: number) => { Column() { Text('页签 ' + this.list[item]) .fontSize(10); Text('页签 ' + this.list[item]) .fontSize(20); Text('页签 ' + this.list[item]) .fontSize(30); Text('页签 ' + this.list[item]) .fontSize(40); Text('页签 ' + this.list[item]) .fontSize(50) .margin(item === 0 ? null : { bottom: 20 }); Text('页签 ' + this.list[item]) .fontSize(60) .margin({ bottom: 20 }) .visibility(item === 0 ? Visibility.Visible : Visibility.None); } .backgroundColor(Color.White) .borderRadius(10); }); } .cachedCount(2) .autoPlay(false) .itemSpace(10) .loop(false) .margin(10) .alignRules({ left: { anchor: '__container__', align: HorizontalAlign.Start }, right: { anchor: '__container__', align: HorizontalAlign.End }, bottom: { anchor: '__container__', align: VerticalAlign.Bottom } }); } .width('100%') .height('100%') .backgroundColor(0xDCDCDC) .padding({ top: 5 }); } }
问题效果预览:

@Entry @Component struct SwiperTextTest { private swiperController: SwiperController = new SwiperController(); private list: number[] = [0, 1]; build() { RelativeContainer() { Swiper(this.swiperController) { ForEach(this.list, (item: number) => { RelativeContainer() { Column() { Text('页签 ' + this.list[item]) .fontSize(10); Text('页签 ' + this.list[item]) .fontSize(20); Text('页签 ' + this.list[item]) .fontSize(30); Text('页签 ' + this.list[item]) .fontSize(40); Text('页签 ' + this.list[item]) .fontSize(50) .margin(item === 0 ? null : { bottom: 20 }); Text('页签 ' + this.list[item]) .fontSize(60) .margin({ bottom: 20 }) .visibility(item === 0 ? Visibility.Visible : Visibility.None); } .backgroundColor(Color.White) .borderRadius(10) .alignRules({ left: { anchor: '__container__', align: HorizontalAlign.Start }, right: { anchor: '__container__', align: HorizontalAlign.End }, bottom: { anchor: '__container__', align: VerticalAlign.Bottom } }); }; }); } .cachedCount(2) .autoPlay(false) .itemSpace(10) .loop(false) .margin(10); } .width('100%') .height('100%') .backgroundColor(0xDCDCDC) .padding({ top: 5 }); } }