12

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

If so, how can it be changed?

Wurstbro
  • 974
  • 1
  • 9
  • 21
  • I don't know at what you're referring with "scaling". The progess for those widgets is set through `setProgress(progressValue)`, if you want a logarithmic behavior then make sure the values you use with the method `setProgress()` are in a logarithmic series. – user Nov 25 '12 at 17:58
  • Let's say I set the min to 0, the max to 10,000 . When the user slides the progress bar to 50% the value would be 5,000 , but I want something like 1,000 e.g. – Wurstbro Nov 25 '12 at 18:20

1 Answers1

5

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)));
amaargiru
  • 61
  • 1
  • 5