是否可以将 Progress- 或 Seekbars 的缩放更改为非线性?
如果是这样,如何改变?
例如:
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)));