獲取屏寬的4種方法

2021-07-25 05:34:43 字數 980 閱讀 6254

方法一:12

3windowmanager wm = (windowmanager) this.getsystemservice(context.window_service);

int width = wm.getdefaultdisplay().getwidth();

int height = wm.getdefaultdisplay().getheight();

方法二:12

3windowmanager wm1 = this.getwindowmanager();

int width1 = wm1.getdefaultdisplay().getwidth();

int height1 = wm1.getdefaultdisplay().getheight();

方法一與方法二獲取螢幕寬度的方法類似,只是獲取windowmanager 物件時的途徑不同。

方法三:12

345windowmanager manager = this.getwindowmanager();

displaymetrics outmetrics = new displaymetrics();

manager.getdefaultdisplay().getmetrics(outmetrics);

int width2 = outmetrics.widthpixels;

int height2 = outmetrics.heightpixels;

方法四:12

345resources resources = this.getresources();

displaymetrics dm = resources.getdisplaymetrics();

float density1 = dm.density;

int width3 = dm.widthpixels;

int height3 = dm.heightpixels;

方法三與方法四類似。

Android獲取螢幕尺寸的4種方法

android獲取螢幕尺寸的4種方法 方法一 windowmanager wm windowmanager this getsystemservice context.window service int width wm.getdefaultdisplay getwidth int height ...

Android獲取螢幕寬度的4種方法

方法一 windowmanager wm windowmanager this getsystemservice context.window service int width wm.getdefaultdisplay getwidth int height wm.getdefaultdispla...

快速獲取別人IP位址的4種方法

那麼對方的ip位址該如何搜查得到呢?這樣的問題你也許會嗤之以鼻,的確,查詢對方計算機的ip位址,實在簡單得不值得一提 可是,要讓你列舉出多種ip位址搜查方法時,你可能就感到勉為其難了。下面,本文就對如何快速 準確地搜查出對方好友的計算機ip位址,提出如下幾種方法,相信能對大家有所幫助 1 郵件查詢法...