HarmonyOS 使用Tabs将barMode设置为Scrollable,数据量大的时显示正常,数据量小的时居中显示,数据量小时如何实现居左显示

HarmonyOS
2024-12-25 13:09:53
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

参考示例如下:

// xxx.ets
@Entry
@Component
struct ListExample {
  private scrollerController = new Scroller()
  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  @State currentIndex: number = 0
  @State fontColor: string = '#606A7E'
  @State selectedFontColor: string = '#FFFFFF'

  build() {
    Column() {
      List({ space: 20, initialIndex: 0, scroller: this.scrollerController }) {
        ForEach(this.arr, (item: number, index: number) => {
          ListItem() {
            Text(item.toString())
              .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
              .fontSize(14)
              .fontWeight(this.currentIndex === index ? 500 : 400)
              .padding({
                left: 10,
                top: 5,
                bottom: 5,
                right: 10
              })
              .textAlign(TextAlign.Center)
              .backgroundColor(this.currentIndex === index ? '#124EE6' : '#F5F6F8')
              .borderRadius(2)
              .width(90)
              .height('100%')
          }
          .onClick(() => {
            this.currentIndex = index
            this.scrollerController.scrollToIndex(this.currentIndex, true, ScrollAlign.CENTER)
          })
        }, (item: string) => item)
      }
      .listDirection(Axis.Horizontal) // 排列方向
      .scrollBar(BarState.Off)
      .friction(0.6)
      .divider({
        strokeWidth: 2,
        color: 0xFFFFFF,
        startMargin: 20,
        endMargin: 20
      }) // 每行之间的分界线
      .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring
      .width('90%')
    }
    .width('100%')
    .height('10%')
    .backgroundColor(0xDCDCDC)
    .padding({ top: 5 })
  }
}
  • 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.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
分享
微博
QQ
微信
回复
2024-12-25 16:46:55


相关问题
HarmonyOS BLE蓝牙发送数据量大问题
1228浏览 • 1回复 待解决
编解码播放大数据量流问题
4133浏览 • 0回复 待解决
sql数据库查询数据量太大查不出来?
4782浏览 • 1回复 待解决
HarmonyOS tabs位置如何显示
564浏览 • 1回复 待解决
Tabs如何才能居显示
1593浏览 • 1回复 待解决