管理中心
您当前正在浏览新版开发者文档中心,目录分类和层级有所调整。点击左侧当前文档分类名称前的“☰”图标,可切换文档分类。 了解新版目录
问题处理与运维开发与测试问题应用框架开发程序框架程序框架(Ability)应用启动时页面周边有白边

应用启动时页面周边有白边

问题现象

应用启动时动效异常,启动图片未铺满屏幕,周边有空白。

背景知识

  • abilities标签:描述UIAbility组件的配置信息,标签值为数组类型,该标签下的配置只对当前UIAbility生效。
  • startWindowIcon标识当前UIAbility组件启动页面图标资源文件。目前startWindowIcon的大小是放多大画多大,没有能力根据设备屏幕或窗口大小自适应调整。

问题定位

  1. 根据entry\src\main\module.json5配置文件中startWindowIcon设置的图片资源,查看该图片资源的大小。
    收起
    自动换行
    深色代码主题
    复制
    1. {
    2. "abilities": [{
    3. "name": "EntryAbility",
    4. "srcEntry": "./ets/entryability/EntryAbility.ets",
    5. "launchType":"singleton",
    6. "description": "$string:description_main_ability",
    7. "icon": "$media:layered_image",
    8. "label": "Login",
    9. "startWindow": "$profile:start_window",
    10. "startWindowIcon": "$media:startWindow",
    11. "startWindowBackground": "$color:red",
    12. "process": ":processTag"
    13. }]
    14. }

  2. 在系统设置中查看屏幕的尺寸,启动页图片的大小与屏幕尺寸不一致。

分析结论

启动页图片的大小与设备分辨率不一致,导致应用启动动画周边有空白。

修改建议

  • 更换启动页图片为与屏幕宽高一致的图片。
  • 开发一个自定义的启动页的方式来实现自定义启动图,而不是只在module.json5配置文件中通过startWindowIcon字段设置启动图。
    收起
    自动换行
    深色代码主题
    复制
    1. @Entry
    2. @Component
    3. struct Index {
    4. pageInfos: NavPathStack = new NavPathStack();
    5. aboutToAppear(): void {
    6. this.pageInfos.pushPath({ name: 'Splash' }); // 跳转到启动页
    7. }
    8. build() {
    9. Navigation(this.pageInfos) {
    10. Stack() {
    11. Text('Hello World')
    12. .fontSize(20)
    13. .fontWeight(FontWeight.Bold);
    14. }
    15. .height('100%')
    16. .width('100%');
    17. }
    18. .hideTitleBar(true)
    19. .height('100%')
    20. .width('100%')
    21. .mode(NavigationMode.Stack);
    22. }
    23. }

    src/main/ets/pages/Splash.ets:

    收起
    自动换行
    深色代码主题
    复制
    1. import { window } from '@kit.ArkUI';
    2. import { common } from '@kit.AbilityKit';
    3. @Builder
    4. export function SplashBuilder() {
    5. Splash();
    6. }
    7. @Entry
    8. @Component
    9. export struct Splash {
    10. pageInfos: NavPathStack = new NavPathStack();
    11. setFull(isFull: boolean) {
    12. let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
    13. window.getLastWindow(context).then((windowClass) => {
    14. windowClass.setWindowLayoutFullScreen(isFull); // 启动页全屏显示
    15. let systemBarPropertiesFull: window.SystemBarProperties = {
    16. statusBarColor: '#00000000',
    17. statusBarContentColor: '#ffffff'
    18. };
    19. let systemBarPropertiesOut: window.SystemBarProperties = {
    20. statusBarColor: '#ffffff',
    21. statusBarContentColor: '#000000'
    22. };
    23. windowClass.setWindowSystemBarProperties(isFull ? systemBarPropertiesFull : systemBarPropertiesOut);
    24. });
    25. }
    26. build() {
    27. NavDestination() {
    28. Stack() {
    29. Image($r('app.media.startWindow')) // $r('app.media.startIcon')需要替换为开发者需要的图片资源文件
    30. .width('100%')
    31. .height('100%')
    32. .syncLoad(true); // 设置图片为同步加载
    33. Column()
    34. .width('100%')
    35. .height('123px')
    36. .linearGradient({
    37. angle: 0,
    38. colors: [[0x11000000, 0.0], [0x00000000, 1.0]]
    39. })
    40. .position({ y: 0 });
    41. }
    42. .height('100%')
    43. .width('100%');
    44. }
    45. .onBackPressed(() => {
    46. this.pageInfos.pop(); // 弹出路由栈栈顶元素
    47. return true;
    48. })
    49. .onDisAppear(() => {
    50. this.setFull(false);
    51. })
    52. .onReady((navContext: NavDestinationContext) => {
    53. this.pageInfos = navContext.pathStack;
    54. this.setFull(true);
    55. setTimeout(() => {
    56. this.pageInfos.pop();
    57. }, 2000);
    58. })
    59. .hideTitleBar(true)
    60. .systemTransition(NavigationSystemTransitionType.NONE)
    61. .height('100%')
    62. .width('100%')
    63. .backgroundColor(Color.White);
    64. }
    65. }

    src/main/resources/base/profile/router_map.json:

    收起
    自动换行
    深色代码主题
    复制
    1. {
    2. "routerMap": [
    3. {
    4. "name": "Splash",
    5. "pageSourceFile": "src/main/ets/pages/Splash.ets",
    6. "buildFunction": "SplashBuilder"
    7. }
    8. ]
    9. }

    src/main/module.json5文件中需添加"routerMap": "$profile:router_map"。

    效果图如下: