如何经常从服务器更新ImageView?

时间:2014-05-12 17:04:46

标签: android

我正在使用Picasso Library从服务器加载图像。我想每秒更新图像大约5-10次。它甚至不能以1帧/秒的速度加载

        protected String doInBackground(String... data) {
        while (refreshImage) {

            runOnUiThread(new Runnable() {
                 @Override
                 public void run() {

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                    Picasso.with(getApplicationContext())
                    .load(getImageURL).into(videoImage);
                    }
                    }, 1000);


                }
            });
        }

        return null;
     }

还有其他方法可以快速帧速率更新ImageView吗?

1 个答案:

答案 0 :(得分:0)

请尝试以下线程功能

new Thread(new Runnable() {
    @Override
    public void run() {
        while (true) {
            if (Chcek online condition here) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //Do your task here...
                    }
                });
            }
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
            }
        }
    }
}).start();