Android的搜索栏与浮点值浮点、Android

2023-09-07 13:33:31 作者:北巷长歌悠

我怎样才能最大值设置为 99,999 和分钟 在搜索栏?

How can I set the max value to 99,999 and min to 0.001 in seekbar ?

推荐答案

您不能。在搜索栏控件只接受其最大和目前的进展整数。你无法控制的最低,因为它始终是 0

You can't. The SeekBar widget only accepts ints for its max and current progress. You can't control the minimum, as it is always 0.

您可以用10的幂,使得小数消失乘以你需要的最大和目前的进展值。在搜索栏仍然会显示进度相同数量,因为它会用十进制值,因为进步是 CurrentValue的/ maxValue(最大值)的比率。正如你将用同样数量乘以两者的比例是相等的。例如:

You could multiply your required maximum and current progress values by a power of 10, such that the decimal goes away. The SeekBar will still show the same amount of progress as it would with a decimal value, as the progress is a ratio of currentValue/maxValue. As you'll be multiplying both by the same number, the ratios are equal. For example:

0.1/10 = 0.01

然而,如果你无论多在0.1和10×10摆脱了小数,你就会得到:

However, if you multiple both 0.1 and 10 by 10 to get rid of the decimal, you get:

1/100 = 0.01 //Same result