Android determine screen orientation at runtime

后端 未结 6 698
清酒与你
清酒与你 2021-02-01 05:41

Here\'s a pseudo code to detect screen rotate event, and decide to retain or changes the screen orientation.

public boolean onOrientationChanges(orientation) {
          


        
6条回答
  •  有刺的猬
    2021-02-01 05:54

    if (this.getWindow().getWindowManager().getDefaultDisplay()
        .getOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
      // portrait mode
    } else if (this.getWindow().getWindowManager().getDefaultDisplay()
               .getOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
      // landscape
    }
    

提交回复
热议问题