如果android模擬器已經啟動後,可以使用快速鍵F12或Ctrl+F11來切換。當然是用命令列僅僅啟動模擬器可以使用參數emulator.exe -skin HVGA-L 來啟動。(還有我發現,我的小鍵盤鎖住的時候,按8然後按7,也橫屏了,雖然不知道什麼原因,還是在這裡補充一下) 需要注意的是,程式會重載onCreate,避免的方法可通過androidmanifest.xml檔案中重新定義方向,以及根據Activity的重寫onConfigurationChanged(Configuration newConfig)方法來控制。 Activity 的 ConfigChanges 屬性官方解釋: 通過設定這個屬性可以使Activity捕捉裝置狀態變化,以下是可以被識別的內容:
CONFIG_FONT_SCALECONFIG_MCCCONFIG_MNCCONFIG_LOCALECONFIG_TOUCHSCREENCONFIG_KEYBOARDCONFIG_NAVIGATIONCONFIG_ORIENTATION
設定方法:將下欄欄位用“|”符號分隔開,例如:“locale|navigation|orientation”Value
Description“mcc“
The IMSI mobile country code (MCC) has changed — that is, a SIM hasbeen detected and updated the MCC.移動國家號碼,由三位元字組成,每個國家都有自己獨立的MCC,可以識別手機使用者所屬國家。“mnc“
The IMSI mobile network code (MNC) has changed — that is, a SIM hasbeen detected and updated the MNC.移動網號,在一個國家或者地區中,用於區分手機使用者的服務商。“locale“
The locale has changed — for example, the user has selected a new language that text should be displayed in.使用者所在地區發生變化。“touchscreen“
The touchscreen has changed. (This should never normally happen.)“keyboard“
The keyboard type has changed — for example, the user has plugged in an external keyboard.鍵盤模式發生變化,例如:使用者接入外部鍵盤輸入。“keyboardHidden“
The keyboard accessibility has changed — for example, the user has slid the keyboard out to expose it.使用者開啟手機硬體鍵盤“navigation“
The navigation type has changed. (This should never normally happen.)“orientation“
The screen orientation has changed — that is, the user has rotated the device.裝置旋轉,橫向顯示和豎向顯示模式切換。“fontScale“
The font scaling factor has changed — that is, the user has selected a new global font size.全域字型大小縮放發生改變 1、不設定Activity的android:configChanges時,切屏會重新調用各個生命週期,切橫屏時會執行一次,切豎屏時會執行一次,網上有的說是,切豎屏會執行兩次,我在android2.3的模擬器和2.3手機上都試了,只有一次。但是在android2.2的模擬器上測試了,切豎屏的時候,會執行兩次聲明周期。2、設定Activity的android:configChanges="orientation"時,切屏還是會重新調用各個生命週期,切橫、豎屏時只會執行一次,而且,切豎屏的時候,最後還會調用onConfigurationChanged 。模擬器會按照以上說的執行,手機的話,不會執行聲明周期,只會執行 onConfigurationChanged3、設定Activity的android:configChanges="orientation|keyboardHidden"時,切屏不會重新調用各個生命週期,只會執行onConfigurationChanged方法