Check orientation on Android phone

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

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

23条回答
  •  死守一世寂寞
    2020-11-22 07:09

    I think this code may work after orientation change has take effect

    Display getOrient = getWindowManager().getDefaultDisplay();
    
    int orientation = getOrient.getOrientation();
    

    override Activity.onConfigurationChanged(Configuration newConfig) function and use newConfig,orientation if you want to get notified about the new orientation before calling setContentView.

提交回复
热议问题