Adjust sample rate of touch input on Android

On Android, is there a way to adjust the sampling rate of touch input?

+6
android touchscreen
source share
2 answers

You cannot stop the system that generates these events, however you can selectively ignore some of the ACTION_MOVE events, since you will see up to 60 per second, each of which reports the same coordinates.

You might want to handle these ACTION_MOVE events after a specified time has passed since the last event, or skip every fifth or 10th event, etc. You will need to experiment and see what works best for you.

Just make sure you don’t miss ACTION_UP , or your application may get into a confused state with touches.

+5
source share

I assume that you are trying to adjust the speed when working with the onTouch function.

  public boolean onTouch(View v, MotionEvent event) { switch(event.getAction()){ case MotionEvent.ACTION_DOWN: downTime = event.getDownTime(); // Do something you want to. break; case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: eventTime = event.getEventTime(); if(eventTime - downTime > 25){ // Do something you want to. } break; } } 

You must declare a long variable downTime and eventTime in your class. Also their unit is ms. Hope this helps you.

2011/7/20 Perhaps you can try:

  Tread.sleep(time); 

See if that helps.

0
source share

All Articles