GestureDetector不捕获所有MotionEvents

时间:2017-10-29 19:55:04

标签: android motionevent

我对Android开发很新。我正在尝试创建一个应用来捕获用户从触摸屏数据中滑动的行为。我按照Android tutorial here中的代码示例,在"检测所有支持的手势"部分中进行了操作。当我使用该应用程序时,我可以看到Logger输出正在响应我的触摸输入。具体来说,在我的onScroll函数中,我有一行:

Log.d(DEBUG_TAG, "onScroll: " + event1.toString() + event2.toString());

正如预期的那样,它向我展示了连接的两个事件。这是一个ACTION_DOWN事件和一个ACTION_MOVE事件,我猜测它分别代表刷卡开始的点和它注册的最后一个点。

问题出在这里:在所有函数中,我只是将MotionEvent添加到ArrayList中,目的是捕获活动的所有事件,最后,当用户单击Button时,我想要做一些事情。事件清单。我尝试在此时进行调试(即onClick)以检查ArrayList的状态,我注意到它缺少所有ACTION_MOVE事件,即来自onScroll的event2,Logger正确地向我展示了它。

我对此非常困惑。我错过了什么?为什么我无法捕获Logger显示的所有事件?这是活动生命周期产生的问题吗?我的代码粘贴在下面。谢谢你的帮助。

public class MainActivity extends AppCompatActivity implements
        GestureDetector.OnGestureListener,
        GestureDetector.OnDoubleTapListener {

    private static final String DEBUG_TAG = "MyGestures";
    private static final String LOG_TAG = "MyLogs";
    private GestureDetectorCompat mDetector;

    private ArrayList<MotionEvent> activityData;

    // Called when the activity is first created.
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Instantiate the gesture detector with the
        // application context and an implementation of
        // GestureDetector.OnGestureListener
        mDetector = new GestureDetectorCompat(this, this);
        // Set the gesture detector as the double tap
        // listener.
        mDetector.setOnDoubleTapListener(this);


        activityData = new ArrayList<>();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        this.mDetector.onTouchEvent(event);
        // Be sure to call the superclass implementation
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onDown(MotionEvent event) {
        Log.d(DEBUG_TAG, "onDown: " + event.toString());
        activityData.add(event);
        return true;
    }

    @Override
    public boolean onFling(MotionEvent event1, MotionEvent event2,
                           float velocityX, float velocityY) {
        Log.d(DEBUG_TAG, "onFling: " + event1.toString() + event2.toString());
        activityData.add(event1);
        activityData.add(event2);
        return true;
    }

    @Override
    public void onLongPress(MotionEvent event) {
        Log.d(DEBUG_TAG, "onLongPress: " + event.toString());
        activityData.add(event);
    }

    @Override
    public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) {
        Log.d(DEBUG_TAG, "onScroll: " + event1.toString() + event2.toString());
        activityData.add(event1);
        activityData.add(event2);
        return true;
    }

    @Override
    public void onShowPress(MotionEvent event) {
        Log.d(DEBUG_TAG, "onShowPress: " + event.toString());
        activityData.add(event);
    }

    @Override
    public boolean onSingleTapUp(MotionEvent event) {
        Log.d(DEBUG_TAG, "onSingleTapUp: " + event.toString());
        activityData.add(event);
        return true;
    }

    @Override
    public boolean onDoubleTap(MotionEvent event) {
        Log.d(DEBUG_TAG, "onDoubleTap: " + event.toString());
        activityData.add(event);
        return true;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent event) {
        Log.d(DEBUG_TAG, "onDoubleTapEvent: " + event.toString());
        activityData.add(event);
        return true;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent event) {
        Log.d(DEBUG_TAG, "onSingleTapConfirmed: " + event.toString());
        activityData.add(event);
        return true;
    }

    public void onClickNext(View view) {

        JSONObject tester = new JSONObject();
        try {
            tester = eventsToJson(activityData);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String urlString = getString(R.string.server_url);

        new PostRequestHandler(this).execute(tester.toString(), urlString);


        //TODO: Handle response
    }

    private JSONObject eventsToJson(ArrayList<MotionEvent> activityData) throws JSONException {
        JSONObject userEventsObj = new JSONObject();
        JSONArray userEvents = new JSONArray();

        for (MotionEvent event : activityData) {
            JSONObject temp = new JSONObject();
            temp.put("Action", event.getAction());
            temp.put("X", (int) event.getX());
            temp.put("Y", (int) event.getY());
            temp.put("EventTime", event.getEventTime());
            temp.put("DownTime", event.getDownTime());    

            userEvents.put(temp);
        }

        userEventsObj.put("UserEvents", userEvents);

        return userEventsObj;
    }

}

更新:以下是日志显示内容的一部分:

10-30 01:06:33.165 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onDown: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.208 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=449.98337, y[0]=627.91046, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453116896, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.225 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=476.3116, y[0]=622.4431, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453116912, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.241 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=505.1541, y[0]=621.4349, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453116929, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.258 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=532.5248, y[0]=618.61414, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453116945, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.274 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=564.44165, y[0]=616.89294, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=453116962, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.291 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=596.44293, y[0]=613.2367, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453116978, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.307 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=628.6956, y[0]=609.60065, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453116995, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.325 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=659.3496, y[0]=605.3122, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117011, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.341 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=687.39014, y[0]=603.4839, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117028, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.357 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=710.6912, y[0]=604.7119, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117045, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.374 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=725.0852, y[0]=608.2169, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=453117061, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.390 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=735.05255, y[0]=612.70935, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117078, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.407 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=743.8147, y[0]=619.6818, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117094, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.423 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=751.9685, y[0]=625.673, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117111, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.440 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=755.5832, y[0]=634.3765, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117127, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.456 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=759.25964, y[0]=643.47815, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=453117144, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.473 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=761.08777, y[0]=656.4128, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117160, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.489 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=761.91425, y[0]=671.6079, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117177, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.507 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=761.8506, y[0]=685.6389, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117193, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.523 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=760.02734, y[0]=700.78613, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117210, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.539 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=752.99744, y[0]=722.8448, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117226, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.555 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=742.76685, y[0]=745.62665, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=453117243, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.570 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=729.58716, y[0]=767.70605, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117258, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.587 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=715.0437, y[0]=790.9412, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117275, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.604 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=696.0053, y[0]=811.3977, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117291, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.621 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=673.6665, y[0]=833.2166, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117308, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.637 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=648.904, y[0]=854.3974, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=453117324, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.653 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=621.0583, y[0]=871.9396, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117341, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.670 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=590.27313, y[0]=888.9372, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117357, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.686 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=556.57916, y[0]=905.7992, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117374, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.703 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=526.4728, y[0]=921.23004, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117390, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.719 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=498.35498, y[0]=936.6223, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117407, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.736 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=475.53375, y[0]=949.354, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=453117423, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.752 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=456.97116, y[0]=960.8024, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117440, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.769 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=441.67072, y[0]=973.4332, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117456, downTime=453116836, deviceId=3, source=0x1002 }
10-30 01:06:33.785 4165-4165/com.emonx.demo.gesturesbasic D/EmonX_Gestures: onScroll: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=414.6161, y[0]=640.6663, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=453116836, downTime=453116836, deviceId=3, source=0x1002 }MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=429.72937, y[0]=985.67145, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=453117473, downTime=453116836, deviceId=3, source=0x1002 }

1 个答案:

答案 0 :(得分:0)

试试这个。

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        this.mDetector.onTouchEvent(event);
        // Be sure to call the superclass implementation
        if(event.action == MotionEvent.ACTION_MOVE){
              Log.d("here");
        }

        return super.onTouchEvent(event);
    }