作者milonga332 ( U U)
看板AndroidDev
标题[问题] WindowManager取得的解析度与实机不符
时间Sat Jul 9 21:52:03 2011
我想取得手机萤幕的解析度
测试的机子为远传小精灵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)
2F:→ milonga332:谢啦..ok了! 07/11 22:58