本篇文章主要介紹了Android獲取設(shè)備屏幕寬高pix值的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
方法一:
WindowManager wm = (WindowManager) this .getSystemService(Context.WINDOW_SERVICE); int width = wm.getDefaultDisplay().getWidth(); int height = wm.getDefaultDisplay().getHeight();
方法二:
WindowManager wm1 = this.getWindowManager(); int width1 = wm1.getDefaultDisplay().getWidth(); int height1 = wm1.getDefaultDisplay().getHeight();
方法一與方法二獲取屏幕寬度的方法類似,只是獲取WindowManager 對(duì)象時(shí)的途徑不同。
方法三:
WindowManager manager = this.getWindowManager(); DisplayMetrics outMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(outMetrics); int width2 = outMetrics.widthPixels; int height2 = outMetrics.heightPixels;
方法四:
Resources resources = this.getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); float density1 = dm.density; int width3 = dm.widthPixels; int height3 = dm.heightPixels;
方法三與方法四類似。
以上所述是小編給大家介紹的Android獲取設(shè)備屏幕寬高pix值的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VEVB武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注