Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Progress/Seekbar scale to be non-linear (e.g. logarithmic)

Is it possible to change the scaling of Progress- or Seekbars to be non-linear?

If so, how can it be changed?

like image 336
Wurstbro Avatar asked Nov 25 '12 17:11

Wurstbro


1 Answers

For example:

weightSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

// place onStartTrackingTouch(SeekBar seekBar) and onStopTrackingTouch(SeekBar seekBar) here

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        userWeight = ((progress * progress) / (1000.0f * 1000.0f)) * (maxWeight - minWeight) + minWeight; // Approximate an exponential curve with x^2.
        }
    });

and vice versa:

weightSeekBar.setProgress((int) (Math.sqrt(((userWeight - minWeight) / (maxWeight - minWeight)) * 1000.0f * 1000.0f)));
like image 56
amaargiru Avatar answered Oct 07 '22 01:10

amaargiru