Adjust touch input sample rate on Android
On Android, is there a way of adjusting the tou开发者_Python百科ch input sample rate?
You can't stop the system generating these events however you can selectively ignore some of the ACTION_MOVE
events as you will see up to 60 per second each reporting the same co-ordinates.
You may wish to only process these ACTION_MOVE
events after a set time since the last event, or skip to every 5th or 10th event etc. You'll have to experiment and see what works best for you.
Just make sure you don't skip ACTION_UP
or your application may get into a confused state with the touches.
I'm supposing you're trying to adjust the rate as you dealing within 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 should declare long variable downTime and eventTime in your class. Also the unit of them is ms. Hope that will help you out.
2011/7/20 Maybe you can try:
Tread.sleep(time);
See if it helps.
精彩评论