3

我正在使用 OnTouchListener 为 ex 捕获多点触控事件。3 指轻敲,我最多可以检测到 2 根手指。即event.getPointerCount()返回最多 2。甚至与onTouchEvent(). 有没有其他 API 来处理这个?我在我的测试设备上启用了 3 指轻敲检测。getPointerCount() 适用于 Android 4.1.2 的 Motorola Droid,但不适用于 Android 4.0.3 的 HTC One V 是我目前所做的:

package com.example.toucheventsample;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.VideoView;

public class TouchEventActivity extends Activity implements OnTouchListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    VideoView videoView = (VideoView) findViewById(R.id.video);
    videoView.setOnTouchListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.touch_event, menu);
    return true;
}

public boolean handleTouchEvent(MotionEvent event) {
    boolean handled = true;
    int action = event.getAction();
    int count = event.getPointerCount();
    switch (action & MotionEvent.ACTION_MASK) {

        case MotionEvent.ACTION_POINTER_UP:
            if (3 == count) {
                // handle 3 finger tap
            }
            break;
    }
    return handled;
}

@Override
public boolean onTouch(View view, MotionEvent event) {
    int count = event.getPointerCount();
    handleTouchEvent(event);
    return true;
}
}
4

0 回答 0