android 設置橫屏豎屏

在android應用開發過程中,尤其是在界面佈局當中,經常會碰到要指定佈局爲橫屏或是豎屏顯示,下面是一些設置android橫豎屏的方法:
  1. 代碼控制
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//設置成全屏模式
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//強制爲橫屏
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//豎屏
  2. xml控制
    在activity裏設置android:screenOrientation的值。
    android:screenOrientation的屬性有以下值:
    unspecified(默認值,由系統判斷狀態自動切換),The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
    landscape,橫屏
    portrait,豎屏
    user(用戶當前設置的orientation值),The user's current preferred orientation.
    behind(下一個要顯示的Activity的orientation值),The same orientation as the activity that's immediately beneath it in the activity stack.
    sensor(傳感器的方向),The orientation determined by a physical orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.
    nosensor(不使用傳感器,這個效果差不多等於unspecified).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified" setting.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章