12

是否可以将 Progress- 或 Seekbars 的缩放更改为非线性?

如果是这样,如何改变?

4

1 回答 1

5

例如:

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.
        }
    });

反之亦然:

weightSeekBar.setProgress((int) (Math.sqrt(((userWeight - minWeight) / (maxWeight - minWeight)) * 1000.0f * 1000.0f)));
于 2015-07-31T08:52:36.183 回答