开发者

getWindowManager().getDefaultDisplay().getHeight() and MotionEvent.getY() returns differnt values?

I'm having issues with how my screen works. I can get the height of the screen by:

getWindowManager().getDefaultDisplay().getHeight(); // == 800 

When I press the screen, I get a specific value:

public boolean onTouch(View v, MotionEvent event){
........
........
      (int) (event.getY(pointerIndex));开发者_如何转开发 // == 701

The problem I'm having is the most I can get on the Y axis is 700!!!

Any suggestions whats going on?

If you need more information please ask.


Ok, I was digging around there for quite a bit but I've found the solution. Thank this thread:

Motionevent.getX and getY

Basically, the touch screen is completely independent from the pixels on your screen. So for example, above the height I was getting was actually the pixels

getWindowManager().getDefaultDisplay().getHeight(); // == 800 

I got the actual height of the touch screen from the view

public boolean onTouch(View v, MotionEvent event){
v.getHeight() // == 724
v.getWidth() // == 480

Hope that helps any poor lost souls!!


I know the solution of the problem. It is caused by the header and the title bar. They are counted in the event of the display.getHeight(). You may remove them this is absolutely up to you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜