的OnClick和onTouch [英] OnClick and onTouch
问题描述
我有一个活动,我有两个imagesViews。
I have a activity where I have two imagesViews.
这给imagesViews有onClickListener,因为我需要知道哪些ImageView的被点击。当我点击choosen照片后,我得到的结果被单击图片。
This to imagesViews has onClickListener, because I need to know which imageView was clicked. After when I click choosen picture I get result which picture was clicked.
我知道需要同样的结果,但我需要知道exacly我点击这个图像。我需要precise坐标被点击此ImageView的位置。我知道,在onTouch方法我有类似的功能,我需要。
I Know need the same result but I need to know where exacly I click on this image. I need precise coordinates where this imageView was clicked. I know that in onTouch method I have functions like I need.
我可以更改onTouch的onClick方法?还是在的onClick可以得到precise坐标?
推荐答案
有没有必要为你使用的onClick
事件,因为你可以用轻松捕捉点击在 onTouch
回调。点击是有一个 ACTION_DOWN
动作序列,几个 ACTION_MOVE
动作和一个 ACTION_UP
的行动。这些可以使用 event.getAction()
方法来获得。如果你得到一个 ACTION_DOWN
事件,然后一个 ACTION_UP
事件 - 这意味着用户只需点击您的查看
。您还可以测量这些事件之间花费的时间,以确保它是一个简单的点击,不长个。而且,当然,你可以使用 event.getX()
和 event.getY()
方法来获取精确的触摸点。希望这有助于。
There is no need for you to use the onClick
event, since you can easily capture the click using the onTouch
callback. A click is a sequence of one ACTION_DOWN
action, several ACTION_MOVE
actions and one ACTION_UP
action. These can be acquired using the event.getAction()
method. If you get an ACTION_DOWN
event and then an ACTION_UP
event - it means that the user has just clicked your View
. You can also measure time spent between these events to be sure that it was a simple click, not a long one. And, of course, you can use the event.getX()
and event.getY()
methods to get the exact touch point. Hope this helps.
这篇关于的OnClick和onTouch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!