doubleTap和刷卡之间切换 [英] switch between doubleTap and Swipe

查看:243
本文介绍了doubleTap和刷卡之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RelativeLayout的,我把一个TouchListener到使用GestureDetector。我已经做了,可检测的双攻,但我怎么能在视图中添加刷卡事件也?

I have a RelativeLayout I am putting a TouchListener into using GestureDetector. I have already done and can detect double tapping but how can I add a swipe event in the view also?

private void myTapEvent(){
        RlContent.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        });

        gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                count++;
                doTaskHere();
                return true;
            }
            @Override
            public boolean onDown(MotionEvent e) {
                return true;
            }
        });
    }

实施刷卡事件发生后,我怎么能之间切换
一。)只允许窃听和禁用刷卡

湾)的禁用窃听并只允许刷卡

推荐答案

在你的 GestureDetector 监听器,添加 onFling 方法。此外,在它们之间切换,你会想在你的类布尔变量,可以进行切换。

In your GestureDetector listener, add the onFling method. Additionally, to switch between them, you will want a boolean variable in your class that can be switched.

private boolean mAllowSwipe = true; // True = swipe, no double-tap; false = double-tap, no swipe

// ...

private void switchGestureMode() {
    if (mAllowSwipe)
        mAllowSwipe = false;
    else
        mAllowSwipe = true;
}

// ...

private void myTapEvent(){
    // ...

    gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (mAllowSwipe) {
                return false;
            }
            count++;
            doTaskHere();
            return true;
        }
        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (!mAllowSwipe) {
                return false;
            }
            // Your logic here
        }
    });
}

// ...

有使用一扔刷卡的一些例子的这里这里,并且有大量更多,如果你谷歌冲刷了一下。

There are some examples of swipe using fling here and here, and there's plenty more if you scour Google a bit.

这篇关于doubleTap和刷卡之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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