gpt4 book ai didi

android - 具有十进制值的 SeekBar

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:57:53 25 4
gpt4 key购买 nike

我是否创建了一个使用十进制值的 SeekBar

比如会显示

0.0, 0.1, 0.2, 0.3, ..., 5.5 >、5.65.7、...、9.910.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com