Check orientation on Android phone

前端 未结 23 1961
庸人自扰
庸人自扰 2020-11-22 06:26

How can I check if the Android phone is in Landscape or Portrait?

23条回答
  •  借酒劲吻你
    2020-11-22 07:06

    there are many ways to do this , this piece of code works for me

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

提交回复
热议问题