#鸿蒙通关秘籍#如何在鸿蒙应用中处理列表的滚动超出安全区?

HarmonyOS
2024-12-10 12:48:10
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
API梦vr彼岸

List 组件配置 expandSafeArea 属性,使 ListItem 在滚动过程中能够延伸到导航条上方:

  1. 确保应用的窗口整体底色一致:

bash import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI';

export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { return; }

    windowStage.getMainWindowSync().setWindowBackgroundColor('#DCDCDC');
  });
}
  • 1.
  • 2.
  • 3.

}

  1. 配置列表代码展示:

bash @Entry @Component struct ListExample { private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

build() {
  Column() {
    List({ space: 20, initialIndex: 0 }) {
      ForEach(this.arr, (item: number) => {
        ListItem() {
          Text('' + item)
            .width('100%')
            .height(100)
            .fontSize(16)
            .textAlign(TextAlign.Center)
            .borderRadius(10)
            .backgroundColor(0xFFFFFF)
        }
      }, (item:number) => item.toString())
    }
    .listDirection(Axis.Vertical)
    .scrollBar(BarState.Off)
    .friction(0.6)
    .divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 })
    .edgeEffect(EdgeEffect.Spring)
    .width('90%')
    .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
  }
  .width('100%')
  .height('100%')
  .padding({ top: 15 })
}
  • 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.

}

分享
微博
QQ
微信
回复
2024-12-10 14:18:57


相关问题
HarmonyOS 安全区域问题
780浏览 • 1回复 待解决
HarmonyOS 安全区域出错
603浏览 • 1回复 待解决
HarmonyOS 安全区域失效
574浏览 • 1回复 待解决
HarmonyOS 设置安全区域不生效
627浏览 • 1回复 待解决
HarmonyOS WebView安全区域问题
417浏览 • 1回复 待解决
HarmonyOS scroll安全区域问题
676浏览 • 1回复 待解决
Flutter 项目在设备安全区如何适配?
680浏览 • 1回复 待解决