#鸿蒙通关秘籍#如何实现固定或滚动的Tab导航栏?

HarmonyOS
2024-11-29 15:34:08
268浏览
收藏 0
回答 2
回答 2
按赞同
/
按时间
樱花语TCP

Tabs组件提供了固定和滚动两种导航栏模式,通过设置barMode参数可以实现:

  1. 固定导航栏设置为BarMode.Fixed
Tabs({ barPosition: BarPosition.End }) {
  ...
}
.barMode(BarMode.Fixed)
  • 1.
  • 2.
  • 3.
  • 4.
  1. 滚动导航栏设置为BarMode.Scrollable
Tabs({ barPosition: BarPosition.Start }) {
  ...
}
.barMode(BarMode.Scrollable)
  • 1.
  • 2.
  • 3.
  • 4.
分享
微博
QQ
微信
回复
2024-11-29 17:31:47
wuyanghcoa

直接看代码:

<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:width="match_parent"
    ohos:height="match_parent"
    ohos:orientation="vertical">

    <TabList
        ohos:width="match_parent"
        ohos:height="wrap_content"
        ohos:tab_mode="fixed">

        <TabItem
            ohos:text="Tab 1"
            ohos:icon="$media:icon_tab1" />

        <TabItem
            ohos:text="Tab 2"
            ohos:icon="$media:icon_tab2" />

        <!-- Add more TabItems as needed -->

    </TabList>

    <TabContent
        ohos:width="match_parent"
        ohos:height="match_parent" />

</DirectionalLayout>
  • 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.
  • 27.
  • 28.
分享
微博
QQ
微信
回复
2024-12-01 16:18:07


相关问题
HarmonyOS Tabs组件Tab滚动问题
1430浏览 • 1回复 待解决
实现tabBar多个tab滚动
1034浏览 • 1回复 待解决
Tab导航tabbar子组件突出上沿显示
2963浏览 • 1回复 待解决