WebView:强制执行顺序显示时序

时间:2011-07-03 05:27:39

标签: webview android-webview

我需要一些教程级别的帮助,以定时顺序显示WebView内容。

下面只是一个测试平台来说明,清单是RelativeLayout中的沼泽标准WebView。

package com.example;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.RelativeLayout;

public class MyActivity extends Activity
{
    private String imgPath;  // empty for testing
    /** Called when the activity is first created. */
    @Override
   public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final WebView mWebView1;
            mWebView1 = (WebView) findViewById(R.id.webviewCard1);
            mWebView1.setLayoutParams(new RelativeLayout.LayoutParams(300,200));

        String fill = "First Content";
        mWebView1.loadDataWithBaseURL(imgPath, fill, "text/html", "utf-8",null);

        /*
        I want the above to load, display First Content (text, image(s), play any
        sound files) then pause for a preset time before doing the same for the 
        Second Content
        */

        fill = "Second Content";
         mWebView1.loadDataWithBaseURL(imgPath, fill, "text/html", "utf-8",null);
    }
}

那么如何在loadDataWithBaseURLs(在相同或不同的WebViews上)之间强制等待n秒呢?

TIA,

1 个答案:

答案 0 :(得分:0)

怎么样: mWebView1.postDelayed(...,timeout);

Executors.newSingleThreadScheduledExecutor()。scheduleWithFixedDelay(command,initialDelay,delay,unit);

我认为任何计时器都可以,只需确保在UI线程上调用webview方法。