如何获得屏幕cordinates对应于整个屏幕,而不是查看感动? [英] How to get screen cordinates corresponding to the whole screen, and not the View touched?

查看:142
本文介绍了如何获得屏幕cordinates对应于整个屏幕,而不是查看感动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林有从我的屏幕有些麻烦取得真正的(X,Y)通过处理一查看项目的触摸事件。

Im having some trouble obtaining the real (x,y) from my screen by handling the touch events of one View Item.

我有这样的:

当我触碰查看项目​​,它给了我与位于其左上角坐标系的原点,如果我滑动手指出来的观点,它给了我负坐标(滑动向上或向左时)。

When I touch the View item, it gives me coordinates with the origin located in his upper-left corner, and if i slide the finger out the view, it gives me negative coordinates (when sliding up or left).

我想获得的视图的位置,在屏幕上,将其添加到第(x,y)坐标,我得到的,所以最后的结果是,(0,0)是在的左上角整个屏幕。

I would like to obtain the View location in the screen, to add it to the (x,y) coordinates that i get, so the final result is that the (0,0) is in the upper-left corner of the whole screen.

我还需要整个屏幕大小,让我知道当手指位于右下角。

I also need the total screen size, so that i know when the finger is located in the lower-right corner.

我怎样才能做到这一点?

How can I achieve this?

感谢。

推荐答案

MotionEvent类有的getX() getY()以方法,它们相对回报的坐标的观点,因为你已经发现了。

MotionEvent class has getX() and getY() methods which return the coordinates relative to the view, as you have discovered.

不过它也有 getRawX() getRawY()方法,根据文档其中说:

However it also has getRawX() and getRawY() methods, which according to the docs say:

返回原生X此事件(或Y)坐标。在屏幕上触摸事件,这是屏幕上的事件的原始位置,之前它已被调整为包含窗口和看法。

Returns the original raw X (or Y) coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.

听起来这是你追求的是什么。

Sounds like this is what you're after.

这篇关于如何获得屏幕cordinates对应于整个屏幕,而不是查看感动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆