如何获得持续的触摸事件? [英] How to get a continuous Touch Event?

查看:156
本文介绍了如何获得持续的触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的类扩展视图,我需要得到持续的触摸事件就可以了。

My class extends View and I need to get continuous touch events on it.

如果我使用:

public boolean onTouchEvent(MotionEvent me) {

    if(me.getAction()==MotionEvent.ACTION_DOWN) {
        myAction();
    }
    return true;
}

...触摸事件被捕获一次。

... the touch event is captured once.

如果我需要得到持续的接触,而无需移动手指是什么? 请告诉我,我不需要使用线程或计时器。我的应用程序已经太多沉重。

What if I need to get continuous touches without moving the finger? Please, tell me I don't need to use threads or timers. My app is already too much heavy.

感谢。

推荐答案

使用如果(me.getAction()== MotionEvent.ACTION_MOVE)。这是不可能保持手指100%完全静止在屏幕上,以便ACTION_MOVE将被调用每次手指的动作,哪怕只是一两个像素。

Use if(me.getAction() == MotionEvent.ACTION_MOVE). It's impossible to keep a finger 100% completely still on the screen so Action_Move will get called every time the finger moves, even if it's only a pixel or two.

您也可以听 me.getAction()== MotionEvent.ACTION_UP - 在此之前,用户必须还有他们的手指在屏幕上

You could also listen for me.getAction() == MotionEvent.ACTION_UP - until that happens, the user must still have their finger on the screen.

这篇关于如何获得持续的触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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