如何检测刷卡事件,而不指提 [英] How to detect swipe event without finger lift

查看:90
本文介绍了如何检测刷卡事件,而不指提的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要递增/递减上的连续的向上滑动/若干向下滑动事件。
我可以实现使用GestureDetector和OnSwipeTouchListener简单的刷卡事件。

I want to increment / decrement a number on continuous swipe up / swipe down events. I could implement simple swipe events using the GestureDetector and OnSwipeTouchListener.

然而,该滑动事件只当手指的滑动后解除检测。
所以递增数+5,我已经使5个人向上滑动的屏幕上。

However, this swipe event is sensed only when the finger is lifted after the swipe. So for incrementing the number to +5, I've to make 5 individual swipe up's on the screen.

我想申请'滑'喜欢动作使得数得到改变,而用户或在屏幕上的任何位置向上滑动了。 (我不想用'滑'窗口小部件)。

I want to apply 'slider' like action such that the number gets changed while user is swiping up or down anywhere on the screen. (I don't want to use the 'Slider' widget).

这可能吗?

任何帮助将是非常感激。
谢谢!

Any help would be really grateful. Thanks!

推荐答案

使用的OnTouchListener:

Use the OnTouchListener:

private float baseX, baseY;

OnTouchListener listener = new OnTouchListener(){
    public boolean onTouch (View v, MotionEvent event)
    {
        switch(event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                //TOUCH STARTED
                baseX = event.getX();
                baseY = event.getY();
                return true;
            case MotionEvent.ACTION_MOVE:
                //FINGER IS MOVING
                //Do your calculations here, using the x and y positions relative to the starting values you get in ACTION_DOWN
                return true;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                //TOUCH COMPLETED
                return true;
        }
    }
}

这篇关于如何检测刷卡事件,而不指提的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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