[問題] WindowManager取得的解析度與實機不符
我想取得手機螢幕的解析度
測試的機子為遠傳小精靈Ideos(320*240)
不過得到的數字卻是427*320
我另外用Garmin-Asus A10來測試,則完全正常(480*320)
不知道大家有碰過這樣的問題嗎?...
我的程式碼試過下面四種方式,對於Ideos都會得到427*320,真奇怪
(程式有設置全螢幕了,所以並不會有title的欄位)
方式一:
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
方式二:
WindowManager windowManager =
(WindowManager)getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(outMetrics);
int width = outMetrics.widthPixels;
int height = outMetrics.heightPixels;
方式三:
WindowManager windowManager =
(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
int width = windowManager.getDefaultDisplay().getWidth();
int height = windowManager.getDefaultDisplay().getHeight();
方式四:
SurfaceHolder holder = getHolder();
Canvas canvas = holder.lockCanvas();
Rect rect;
canvas.getClipBounds(rect);
int width = rect.right;
int height = rect.bottom;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.217.147.147
※ 編輯: milonga332 來自: 61.217.147.147 (07/09 22:01)
推
07/10 10:02, , 1F
07/10 10:02, 1F
→
07/11 22:58, , 2F
07/11 22:58, 2F
AndroidDev 近期熱門文章
PTT數位生活區 即時熱門文章