简体   繁体   中英

how to set a seekbars progress with a decimal value that is a float, accuratly?

hey guys i am trying to make a set temperature app which has a seek bar and a textview. the readings of my temperature include values like 33.3 and 34.5. I know the code fore setting a seekbars progress is

seekbarTemperature.setProgress(int);

but i want to use float values like 33.3 or 39.8. if i convert a float into an int it rounds the value up to a whole number like 33 or 34. this will not position my seekbar properly because my seekbar will be positioned at 33 when my textview says 33.3. As i have also set the seekbar to increment or decrement by 0.1 it is vital that my seekbar is positioned accurately to the decimal. So can someone tell me how to set the seekbars progress position exactly to ie 33.4 not 33 or 34?

you can not show ProgressBar progress with double value. but you can go for a simple mathematics.

set the ProgressBar maximum progress to 1000.
now when you want to show progress with value 33.3, update the ProgressBar with 333 like

 progressBar.setProgress(333);

相反,要将搜索栏从0变为100 ,可以将其从0变为100033.4应该为334

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM