我有完全相同的问题,并想出了我自己降低灵敏度的方法。当我离开滑块并且由于手指厚度等原因意外重新定位时,我的问题发生了。所以我写了一个计时器来查看是否选择了一段时间并在离开搜索栏时捕捉到这个位置。这种方法有点笨拙,但这是我能想到的最好的方法,因为我不想要上面建议的 +/- 按钮。它很适合我的需要。这是任何有兴趣的人的代码:
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int lastProgress = 0;
Timer endTimer = null;
boolean timerExpired = false;
class SeekBarTimerTask extends TimerTask {
public void run() {
timerExpired = true;
}
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(timerExpired == false) {
// clean up the previous timer and start a new one
setTimer();
}
else {
// if the timer has expired, do not honor small variations of 2%
if(Math.abs(progress - lastProgress) <= seekBar.getMax() * 0.02) {
seekBar.setProgress(lastProgress);
return;
}
else {
// The variation is not small. This means that the seekbar position change
// was intentional. Honor it and schedule the timer again.
setTimer();
}
}
lastProgress = progress;
}
public void onStartTrackingTouch (SeekBar seekBar) {}
public void onStopTrackingTouch (SeekBar seekBar) {
timerExpired = false;
endTimer.cancel();
endTimer.purge();
}
private void setTimer() {
if(endTimer != null) {
endTimer.cancel();
endTimer.purge();
}
timerExpired = false;
endTimer = new Timer();
endTimer.schedule(new SeekBarTimerTask(), 300);
}
});