Nikola Lukic Nikola Lukic - 1 year ago 99
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.


enter image description here

Answer Source

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)){
}else if(seekBar.getProgress() <= limit){

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download