Tab组件页面切换时,如何不显示中间过渡的tab页

目前页面在跨页点击tab页的时,会显示中间过渡页面。

HarmonyOS
2024-07-22 11:58:17
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

如果需要做动画,规格上是一定要从1,2,3,4进行运动的,如果不想显示中间过渡页,可以通过设置.animationDuration(0)就看不到了。

参考代码

// xxx.ets 
@Entry 
@Component 
struct TabsExample { 
  @State fontColor: string = '#182431' 
  @State selectedFontColor: string = '#007DFF' 
  @State currentIndex: number = 0 
  private controller: TabsController = new TabsController() 
 
  @Builder 
  tabBuilder(index: number, name: string) { 
    Column() { 
      Text(name) 
        .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor) 
        .fontSize(16) 
        .fontWeight(this.currentIndex === index ? 500 : 400) 
        .lineHeight(22) 
        .margin({ top: 17, bottom: 7 }) 
      Divider() 
        .strokeWidth(2) 
        .color('#007DFF') 
        .opacity(this.currentIndex === index ? 1 : 0) 
    }.width('100%') 
  } 
 
  build() { 
    Column() { 
      Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) { 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor('#00CB87') 
        }.tabBar(this.tabBuilder(0, 'green')) 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor('#007DFF') 
        }.tabBar(this.tabBuilder(1, 'blue')) 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor('#FFBF00') 
        }.tabBar(this.tabBuilder(2, 'yellow')) 
 
        TabContent() { 
          Column().width('100%').height('100%').backgroundColor('#E67C92') 
        }.tabBar(this.tabBuilder(3, 'pink')) 
      } 
      .vertical(false) 
      .barMode(BarMode.Fixed) 
      .barWidth(360) 
      .barHeight(56) 
      //设置动画时间为0,即可解决跨页切换显示中间过渡页面 
      .animationDuration(0) 
      .onChange((index: number) => { 
        this.currentIndex = index 
      }) 
      .width(360) 
      .height(296) 
      .margin({ top: 52 }) 
      .backgroundColor('#F1F3F5') 
    }.width('100%') 
  } 
}
分享
微博
QQ
微信
回复
2024-07-22 19:46:29
相关问题
Tab控件切换问题有哪些?
57浏览 • 1回复 待解决
HarmonyOS Navigation和Tab组件问题
404浏览 • 1回复 待解决
Tab导航栏tabbar子组件突出上沿显示
1984浏览 • 1回复 待解决
请问一下tab按钮组切换效果
660浏览 • 1回复 待解决
Tab组件Tabbar中字体颜色如何修改
920浏览 • 1回复 待解决
想实现tabBar多个tab滚动
119浏览 • 1回复 待解决
HarmonyOS Tab组件无法响应onPageShow
116浏览 • 1回复 待解决
HarmonyOS web加载页面图片不显示
216浏览 • 1回复 待解决
TAB菜单栏相关问题如何解决?
129浏览 • 1回复 待解决