简体   繁体   中英

Detecting a % Change

Hello so im making a loading bar so my loading bar should be 246px so I worked out how many PX it should move per % and that answer was 2.46 Px now my issue is how do i detect the % change so at the moment i have this

if(Math.round(sumCount / size * 100.0) == 1) {
                        LoadingBar.setLocation((int)-243.54,280);
                    } else if(Math.round(sumCount / size * 100.0) == 2) {
                         LoadingBar.setLocation((int)-241.08,280);
                    } else if(Math.round(sumCount / size * 100.0) == 3) {
                         LoadingBar.setLocation((int)-238.62,280);
                    } else if(Math.round(sumCount / size * 100.0) == 4) {
                         LoadingBar.setLocation((int)-236.16,280);
                    } else if(Math.round(sumCount / size * 100.0) == 5) {
                         LoadingBar.setLocation((int)-233.7,280);
                    } else if(Math.round(sumCount / size * 100.0) == 6) {
                         LoadingBar.setLocation((int)-231.24,280);
                    } else if(Math.round(sumCount / size * 100.0) == 7) {
                         LoadingBar.setLocation((int)-228.78,280);
                    }

And I really dont want to do this as it will take ages and its a way to do it i was wondering if anyone could think or show me a better way to do this so

Math.round(sumCount / size * 100.0)

Is the % it downloded and -246 is where the loading bar is drawn just off the screen

In your loop or piece of code, that triggers the loading bar change, just add this:

LoadingBar.setLocation((int)(246-2.46*Math.round(sumCount / size * 100.0)));

Does it make sense?

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