如何获取设备屏幕横竖屏状态
=============

方法一：利用媒体查询

import { mediaquery, UIContext } from '@kit.ArkUI';

_// Store context in EntryAbility_
const context = AppStorage.get("context") as UIContext;
let listener = context.getMediaQuery().matchMediaSync('(orientation: landscape)'); _// Listen to landscape events_
function onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) {
  console.info('mediaQueryResult.matches:' + mediaQueryResult.matches)
  if (mediaQueryResult.matches) {
 _   // do something here_
  } else {
  _  // do something here_
  }
}
listener.on('change', onPortrait) _// Register callback_
listener.off('change', onPortrait) _// Unregister callback_

@Entry
@Component
struct Index {
  build() {
    Column() {
      Column() {
        Text('test')
      }
      .width('100%')
    }
    .height('100%')
    .width('100%')
    .justifyContent(FlexAlign.End)
  }
}

方法二：

可通过[display.getDefaultDisplaySync](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-display#displaygetdefaultdisplaysync9)方法获取到[Display](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-display#display)实例，再通过此实例获取其rotation属性即可获取屏幕横竖屏状态。

import { display, window } from '@kit.ArkUI';

@Entry
@Component
struct WindowRotation {
  build() {
    Text("Scroll Area")
      .width("100%")
      .height("100%")
      .backgroundColor(0X330000FF)
      .fontSize(16)
      .textAlign(TextAlign.Center)
      .onClick(() => {
        window.getLastWindow(this.getUIContext().getHostContext(), (err, win) => {
          let cutOutInfo = win.getWindowAvoidArea(window.AvoidAreaType.TYPE\_SYSTEM\_GESTURE)
          console.log(JSON.stringify(cutOutInfo))
          if (window.Orientation.AUTO\_ROTATION) {
            let rotation: number = display.getDefaultDisplaySync().orientation _// Get current screen orientation enum value_
            console.log('' + rotation);
            if (rotation == 0) {
              console.log("CutOutInfo Portrait data: " + JSON.stringify(cutOutInfo));
            } else if (rotation == 1) {
              console.log("CutOutInfo Landscape data: " + JSON.stringify(cutOutInfo));
            } else if (rotation == 2) {
              console.log("CutOutInfo Reverse portrait data: " + JSON.stringify(cutOutInfo));
            } else {
              console.log("CutOutInfo Reverse landscape data: " + JSON.stringify(cutOutInfo));
            }
          }
        })
      })
  }
}