我是否创建了一个使用十进制值的 SeekBar
?
比如会显示
0.0
, 0.1
, 0.2
, 0.3
, ..., 5.5
>、5.6
、5.7
、...、9.9
、10.0
最佳答案
SeekBar 默认值为 0 到 100 之间的值。当从 SeekBar 的更改监听器调用 onProgressChanged
函数时,进度号将在 progress
参数中传递。
如果您想将此进度转换为从 0.0 -> 10.0 的小数来显示或处理,您需要做的就是在收到进度值时将进度除以 10,然后将该值转换为 float 。下面是一些示例代码:
aSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float value = ((float)progress / 10.0);
// value now holds the decimal value between 0.0 and 10.0 of the progress
// Example:
// If the progress changed to 45, value would now hold 4.5
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
关于android - 具有十进制值的 SeekBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6197674/