我正在尝试在android中做触摸板,我有问题。 当我按下鼠标按钮时,我的手指无法移动到屏幕上。
鼠标监听器:
mouse1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
client.send("B:bPressed1");
Log.d("Touchpad", "Mouse1 pressed");
} else if (event.getAction() == MotionEvent.ACTION_UP) {
client.send("B:bRelease1");
Log.d("Touchpad", "Mouse1 released");
}
return false;
}
});
覆盖onTouchEvent以获取鼠标位置:
@Override
public boolean onTouchEvent(MotionEvent e) {
this.gDetector.onTouchEvent(e);
float x = e.getX();
float y = e.getY();
switch (e.getAction()) {
case MotionEvent.ACTION_MOVE:
int dx = (int) (x - mPreviousX);
int dy = (int) (y - mPreviousY);
Log.i("Touchpad", dx + "/" + dy);
client.send("M:" + dx + "/" + dy);
}
mPreviousX = x;
mPreviousY = y;
return super.onTouchEvent(e);
}