Nikola Lukic Nikola Lukic - 10 days ago 5
Android Question

Android seekbar how to block dragging in range of progress value

To make clear , i want to prevent dragging at 80% of max value also left margin 20% . Dragging range will be (from 20% to the 80%) .

I just need to know is it possible make it from existing method clear and easy.

screenshot

enter image description here

Answer

You can do it with onProgressChanged with a very basic calculations. If the min value is 0 and max value is 200 and we want to limit the first and last 20%. In the onProgressChanged method you just:

// I think this two variables should be out of the method
int limit = ((20 * 200) / 100);
int maxValue = seekBar.getMax();
if(seekBar.getProgress() >= (maxValue - limit)){
    seekBar.setProgress(maxValue);
}else if(seekBar.getProgress() <= limit){
    seekBar.setProgress(limit);
}

This has been done on the fly, it isn't tested and probably there is something wrong, but that is the idea

Comments