HarmonyOS鸿蒙Next中tabs设置了scrollable(true)但是还是无法滚动

HarmonyOS鸿蒙Next中tabs设置了scrollable(true)但是还是无法滚动

Tabs({ barPosition:BarPosition.Start, controller:this.controller }){ TabContent(){ InvestPageSubView({ appId: ‘20222000’, defaultUrl: ‘/neo_wealth/wealth/wealthSelection.html’ }) }.tabBar(this.InvestTopTabBuilder(0, true,’’)) TabContent(){ InvestPageSubView({ appId: ‘20222000’, defaultUrl: ‘/neo_wealth/wealth/optional.html’ }) }.tabBar(this.InvestTopTabBuilder(1, false,‘自选’)) TabContent(){ InvestPageSubView({ appId: ‘20222001’, defaultUrl: ‘/neo_invest/invest/current.html’ }) }.tabBar(this.InvestTopTabBuilder(2, false,‘活期+’)) TabContent(){ InvestPageSubView({ appId: ‘20222001’, defaultUrl: ‘/neo_invest/invest/regular.html’ }) }.tabBar(this.InvestTopTabBuilder(3, false,‘理财’)) TabContent(){ InvestPageSubView({ appId: ‘20222001’, defaultUrl: ‘/neo_invest/invest/invest.html’ }) }.tabBar(this.InvestTopTabBuilder(4, false,‘投资’)) } .alignRules({ top: { anchor: ‘InvestBar’, align: VerticalAlign.Bottom }, }) .id(‘MineH5’) .margin({ top: 8 }) .scrollable(true) .barMode(BarMode.Fixed) .barWidth(360) .barHeight(56) .animationDuration(50) .onChange((index: number) => { this.currentIndex = index })


更多关于HarmonyOS鸿蒙Next中tabs设置了scrollable(true)但是还是无法滚动的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

可参考一下这个demo

@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('50%')
  }

  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.Scrollable)
      .barWidth(360)
      .barHeight(56)
      .animationDuration(400)
      .onChange((index: number) => {
        this.currentIndex = index
      })
      .width(360)
      .height(296)
      .margin({ top: 52 })
      .backgroundColor('#F1F3F5')
    }
    .width('100%')
  }
}

更多关于HarmonyOS鸿蒙Next中tabs设置了scrollable(true)但是还是无法滚动的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,如果tabs组件设置了scrollable(true)但仍然无法滚动,可能是以下原因导致的:

  1. 布局限制:tabs组件的父容器可能设置了固定宽度或高度,导致tabs无法正确计算可滚动的区域。确保父容器的布局不会限制tabs的滚动行为。

  2. 内容不足:如果tabs中的内容不足以超出容器的可见区域,滚动功能将不会生效。确保tabs中的内容足够多,能够触发滚动。

  3. 样式问题:某些自定义样式可能影响了tabs的滚动行为。检查是否有样式覆盖了默认的滚动行为,例如overflow属性被设置为hidden

  4. 版本兼容性:确保使用的HarmonyOS SDK版本支持scrollable(true)功能。某些早期版本可能存在兼容性问题。

  5. 组件嵌套:如果tabs组件被嵌套在其他可滚动组件中,可能会导致滚动冲突。检查是否有其他滚动容器影响了tabs的滚动。

  6. 事件拦截:某些事件监听器可能拦截了滚动事件,导致tabs无法正常滚动。检查是否有事件监听器干扰了滚动行为。

如果以上原因都已排除,建议重新检查代码实现,确保scrollable(true)被正确应用,并且没有其他因素干扰滚动功能。

在HarmonyOS鸿蒙Next中,即使为Tabs组件设置了scrollable(true),如果内容不足以超出容器宽度,Tabs仍然不会滚动。请检查以下可能的原因:

  1. 内容宽度不足:确保Tab数量足够多,使得总宽度超过Tabs容器宽度。
  2. 布局限制:检查父容器的布局约束,确保Tabs组件有足够的空间进行滚动。
  3. 样式问题:确认是否有CSS样式限制了Tabs的宽度或滚动行为。

如果问题仍未解决,建议使用调试工具检查Tabs的实际宽度和布局。

回到顶部