我想要一个扩展的SurficeView类,当用户触摸屏幕时(比如onKeyDown),它会做一些事情。
像这样:
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.e("Touching", "Touching the Screen");
return true;
}
当用户触摸屏幕时,我希望我的LogCat被垃圾邮件(只是测试)直到我没有触摸它,但它只显示消息两次:当我触摸时和我释放时。
答案 0 :(得分:1)
这是OnTouch侦听器的不同行为
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(TAG, "mode=DRAG");
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
Log.i("Tag", "1");
break;
case MotionEvent.ACTION_POINTER_DOWN:
Log.i("Tag", "2");
break;// return
case MotionEvent.ACTION_UP:
Log.i("Tag", "3");
case MotionEvent.ACTION_POINTER_UP:
Log.i("Tag", "4");
break;
case MotionEvent.ACTION_MOVE:
Log.i("Tag", "5");
break;
}
return true;
}
});
答案 1 :(得分:0)
写入登录以下操作之一,如:
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction==MotionEvent.ACTION_DOWN){
Log.e("Touching", "Touching the Screen");
}
else if(event.getAction==MotionEvent.ACTION_UP){
Log.e("Touching up", "Touching the Screen up");}
return true;
}