From 4cc14d9ad875f1da89d42b0c6c2f7bdf1e64bfaf Mon Sep 17 00:00:00 2001 From: cq_0418 Date: Wed, 2 Jul 2025 15:26:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3setRelativePositionToParentWi?= =?UTF-8?q?ndowEnabled=E6=8E=A5=E5=8F=A3=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cq_0418 --- .../apis-arkui/arkts-apis-window-Window.md | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/zh-cn/application-dev/reference/apis-arkui/arkts-apis-window-Window.md b/zh-cn/application-dev/reference/apis-arkui/arkts-apis-window-Window.md index 4ac04b161c6..aeb910a8adb 100644 --- a/zh-cn/application-dev/reference/apis-arkui/arkts-apis-window-Window.md +++ b/zh-cn/application-dev/reference/apis-arkui/arkts-apis-window-Window.md @@ -8608,7 +8608,7 @@ setRelativePositionToParentWindowEnabled(enabled: boolean, anchor?: WindowAnchor 2、当子窗调用该接口后,立即使其显示位置跟随主窗并保持相对位置不变,除非传入false再次调用该接口,否则效果将持续。 -3、当子窗调用该接口后,再调用[moveWindowTo()](#movewindowto9)、[maximize()](#maximize12)等修改窗口位置或大小的接口将不生效。 +3、当子窗调用该接口后,再调用[moveWindowTo()](#movewindowto9)、[maximize()](#maximize12)修改窗口位置或大小的接口将不生效。 该接口调用生效后,[setFollowParentWindowLayoutEnabled()](#setfollowparentwindowlayoutenabled17)接口调用不生效。 @@ -8616,8 +8616,6 @@ setRelativePositionToParentWindowEnabled(enabled: boolean, anchor?: WindowAnchor **系统能力:** SystemCapability.Window.SessionManager -**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -8639,7 +8637,6 @@ setRelativePositionToParentWindowEnabled(enabled: boolean, anchor?: WindowAnchor | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------------------------------------------------------ | -| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 801 | Capability not supported.Function setRelativePositionToParentWindowEnabled can not work correctly due to limited device capabilities.| | 1300002 | This window state is abnormal. | | 1300003 | This window manager service works abnormally. | @@ -8648,19 +8645,33 @@ setRelativePositionToParentWindowEnabled(enabled: boolean, anchor?: WindowAnchor **示例:** ```ts +import { window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; +import { UIAbility } from '@kit.AbilityKit'; -try { - let windowClass: window.Window = window.findWindow("subWindow"); - let enabled: boolean = true; - let promise = windowClass?.setRelativePositionToParentWindowEnabled(enabled); - promise.then(() => { - console.info('Succeeded in setting the sub window supports relative position to parent window.') - }).catch((err: BusinessError) => { - console.error(`Failed to set the sub window supports relative position to parent window. Cause code: ${err.code}, message: ${err.message}`); - }); -} catch (exception) { - console.error(`Failed to set the sub window supports relative position to parent window. Cause code: ${exception.code}, message: ${exception.message}`); +export default class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (loadError: BusinessError) => { + if (loadError.code) { + console.error(`Failed to load the content. Cause code: ${loadError.code}, message: ${loadError.message}`); + return; + } + console.info("Succeeded in loading the content."); + windowStage.createSubWindow("subWindow").then((subWindow: window.Window) => { + if (subWindow == null) { + console.error("Failed to create the subWindow. Cause: The data is empty"); + return; + } + subWindow.setRelativePositionToParentWindowEnabled(true).then(() => { + console.info("after set relative position to parent window enabled"); + }).catch((error: BusinessError) => { + console.error(`setRelativePositionToParentWindowEnabled failed. ${error.code} ${error.message}`); + }) + }).catch((error: BusinessError) => { + console.error(`createSubWindow failed. ${error.code} ${error.message}`); + }) + }); + } } ``` -- Gitee