HarmonyOS 横屏后布局问题?

如题:HarmonyOS 横屏后布局问题?

阅读 568
1 个回答

问题场景

使用window.setPreferredOrientation设置强制横屏后,Navigation宽度正常,但其中内容组件的宽度不对

可以使用 onPageShow onPageHide来设置页面级别的横屏

onPageShow(): void {
  // window.getLastWindow(getContext(this), (err, win) => {
  // win.setPreferredOrientation(window.Orientation.LANDSCAPE_INVERTED)
  // })
}

onPageHide(): void {
  window.getLastWindow(getContext(this), (err, win) => {
  win.setPreferredOrientation(window.Orientation.PORTRAIT)
})

或者在上一个界面跳转第二个界面的时候调用横屏,demo以下

Button('界面跳转')
  .onClick(()=>{
    window.getLastWindow(getContext(this), (err, win) => {
      win.setPreferredOrientation(window.Orientation.LANDSCAPE_INVERTED)
    })

    router.pushUrl({
      url:"pages/Index2"
    })
  })

setPreferredOrientation的使用请详细参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5\#setpreferredorientation9

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进