#鸿蒙通关秘籍#如何实现Tabs组件的页面滑动切换功能?

HarmonyOS
2024-12-04 14:06:47
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Y影歌EDIF

设置scrollable为true,使页面可以通过滑动改变。如下代码所示:

@Entry
@Component
struct TabsScrollableExample {
  @State currentIndex = 0;
  
  build() {
    Tabs({ index: this.currentIndex, scrollable: true }) {
      TabContent() {
        Column().width('100%').height('100%').backgroundColor('#00CB87');
      }.tabBar('Page 1')

      TabContent() {
        Column().width('100%').height('100%').backgroundColor('#007DFF');
      }.tabBar('Page 2')
      
      TabContent() {
        Column().width('100%').height('100%').backgroundColor('#FFBF00');
      }.tabBar('Page 3')
    }
    .onChange((index) => {
      this.currentIndex = index;
    });
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
分享
微博
QQ
微信
回复
2024-12-04 15:43:20
相关问题