我想在三个手指触摸屏幕时关闭我的应用程序(就像 mac os 一样)。在我的应用程序中,我同时使用了碎片和视图寻呼机,但我不明白如何使用 event.getAction() 和 Action Mask。
我都用过
MotionEvent.ACTION_UP
MotionEvent.ACTION_POINTER_DOWN:
但它们不起作用。
当使用不同的 ACTION_MASKED 应用程序时,会被多次调用。
int maxPointercount=0;
int previousPointercount=0;
public boolean onTouch(View v, MotionEvent event) {
int currentpointerCount = event.getPointerCount();
System.out.println("My pointer....." + currentpointerCount);
int action = event.getAction() & MotionEvent.ACTION_MASK;
System.out.println("pre......."+previousPointercount);
System.out.println("max......."+maxPointercount);
if(maxPointercount < previousPointercount){
maxPointercount = currentpointerCount;
}
previousPointercount = currentpointerCount;
if(action==MotionEvent.ACTION_) {
if(maxPointercount>=3){
maxPointercount = 0;
Toast.makeText(MyclassActivity.this,"FingerToched!!"Toast.LENGTH_SHORT).show();
Intent intent = newIntent(MyclassActivity.this,DashboardActivity.class);
startActivity(intent);
finish();
//your code that will run 1 time
}
maxPointercount = 0;
previousPointercount = 0;
}
return super.onTouchEvent(event);
}