如何使进度条加载 15 秒? [英] how make Progress Bar for 15 sec loading?

查看:40
本文介绍了如何使进度条加载 15 秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码

progressBar = (ProgressBar) findViewById(R.id.progressBar);
            textView = (TextView) findViewById(R.id.secdelay);
            // Start long running operation in a background thread
            new Thread(new Runnable() {
                public void run() {
                    while (progressStatus < 15) {
                        progressStatus += 1;
                        // Update the progress bar and display the

                        //current value in the text view
                        handler.post(new Runnable() {
                            public void run() {
                                progressBar.setProgress(progressStatus);
                                textView.setText(progressStatus+"/"+progressBar.getMax());
                            }
                        });
                        try {
                            // Sleep for 200 milliseconds.

                            //Just to display the progress slowly
                            Thread.sleep(1500);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).start();

现在它的加载很好,我想要 15ec 的进度条怎么办?希望你们明白什么意思.一个 15 秒的加载进度条,我看到了它的跳跃动画,任何让它平滑的方法.提前感谢菜鸟问题抱歉只是一个学习者

now its loading fine , I want to progress bar for 15ec how to do it ? hope you guys understand what meant . a 15 sec loading progress bar and I saw its jumping the animation, any way to make it smooth . thanks in advance noob question sorry just a learner

推荐答案

您可以将进度条的最大值设置为 15secs*5 = 75 以启用更新更小的叮咬"以获得更流畅的动画.

You can set the max of the progress bar to 15secs*5 = 75 to enable updating smaller 'bites' for a smoother animation.

然后每 200 毫秒更新一次进度.

Then update progress by 1 each 200ms.

progressBar.setMax(75)
while (progressStatus < 75) {
    progressStatus += 1;
    // Update the progress bar and display the

    //current value in the text view
    handler.post(new Runnable() {
        public void run() {
            progressBar.setProgress(progressStatus);
            textView.setText(progressStatus+"/"+progressBar.getMax());
        }
    });
    try {
        // Sleep for 200 milliseconds.

        //Just to display the progress slowly
        Thread.sleep(200);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

使用最多 150 毫秒也只能睡眠 100 毫秒.

Could also sleep only 100ms using a max of 150.

这篇关于如何使进度条加载 15 秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆