2011-03-09 175 views
0

我在Netbeans項目中的屏幕尺寸是QVGA-L(240X320) 並在WVGA800(480X800) 中運行AVD首先我不確定這兩者之間有什麼不同。 但我真正的問題是,實際屏幕尺寸爲213X270 雖然,當我把這個代碼:Android屏幕尺寸

WindowManager windowManager = getWindowManager(); 
Display defaultDisplay = windowManager.getDefaultDisplay(); 
width = defaultDisplay.getWidth(); 
height = defaultDisplay.getHeight(); 

寬度= 240 高度= 320

,但是當我再次按下右BUTTOM角落 我從onTouchListener的MotionEvent獲得213X270

我在做什麼錯?

回答

0

我想也許你沒有考慮通知欄頂部和應用程序標題欄。如果你有你的應用程序默認佈局設置有主在RES /佈局/ filename.xml中的ID,您可以嘗試使用這個:

LinearLayout layout = (LinearLayout) findViewById(R.id.main); 
int width = layout.getWidth(); 
int height= layout.getHeight(); 
+0

否(0,0)低於條形。我不使用XML佈局我做佈局=新的RelativeLayout(this); – Rami 2011-03-09 21:22:10

0

只是猜測,但也許你需要得到應用程序上下文而不是本地上下文。

Context context = myContext.getApplicationContext(); 
WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); 
Display display = wm.getDefaultDisplay(); 
width = defaultDisplay.getWidth(); 
height = defaultDisplay.getHeight(); 

我很感興趣,看看結果如何,因爲我在我自己的應用程序中有類似的代碼。 :-)所以,最好自己稍後再玩。

+0

仍然給我320X480:| – Rami 2011-03-09 21:19:51