Android设置横屏或竖屏

两种方法

  • 代码设置:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//横屏  
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏  
  • xml设置:
    在activity里设置android:screenOrientation的值。
    android:screenOrientation的属性有以下值:
    unspecified (默认值,由系统判断状态自动切换)。
    landscape 横屏。
    portrait 竖屏。
    user (用户当前设置的orientation值)。
    behind (下一个要显示的Activity的orientation值)。
    sensor(传感器的方向)。
    nosensor(不使用传感器,这个效果差不多等于unspecified)。
android:screenOrientation="portrait"

猜你喜欢

转载自blog.csdn.net/u011181222/article/details/52297331