目录

How do I ensure that the layout of the floating window is normal when I drag the floating window to the extended monitor on a HarmonyOS computer?

Possible Causes

The vp-to-px conversion formula is px = px value = vp value × logical pixel density of the display.

The size unit of ArkTS page components is vp. When you drag the floating window to the extended monitor, the actual display size px of the component changes due to the change of the logical pixel density of the display device. If the window size is not adjusted accordingly, the floating window layout will be abnormal.

Solution

Use on('densityUpdate') to listen to the changes of the logical pixel density of the screen where the floating window is located. When the logical pixel density changes, adjust the actual size (px) of the floating window through the resize API based on the original vp of the window to ensure that the floating window layout is normal.