android判斷手機螢幕橫豎屏

2021-06-07 20:26:10 字數 531 閱讀 5959

在乙個activity顯示中判斷當前螢幕橫豎屏情況有幾種方法:

configuration configuration = getresources().getconfiguration();

if (configuration.orientation == configuration.orientation_landscape)

第二種方法:

int requestedorientation = getrequestedorientation();

if (requestedorientation == activityinfo.screen_orientation_landscape)

獲取螢幕方向還可以用方法:

getwindow().getattributes().screenorientation;

windowmanager mgr = getwindowmanager();

int orientation = mgr.getdefaultdisplay().getorientation();

iOS 獲取判斷手機螢幕尺寸,並判斷手機系統版本

通常情況,我們會需要獲取手機系統和手機尺寸,而且為了方便我們還要設定成全域性的 巨集定義,在任何乙個類都可以使用 建完以後 uidevice currentdevice systemversion floatvalue 手機系統 define ios7 or later uidevice curre...

移動端判斷手機橫豎屏狀態

在做移動端開發的時候,在html頁面head中加入如下 設定螢幕寬度為裝置寬度,禁止使用者手動調整縮放,頁面初始縮放程度為1 1.寫在同乙個css檔案中 media screen and orientation portrait media screen and orientation landsc...

移動端判斷手機橫豎屏狀態

在做移動端開發的時候,在html頁面head中加入如下 name viewport content width device width,user scalable no,initial scale 1 設定螢幕寬度為裝置寬度,禁止使用者手動調整縮放,頁面初始縮放程度為1 1.寫在同乙個css檔案中...