WebView:强制顺序显示时序
我需要一些教程级别的帮助来按时间顺序显示 WebView 内容。
下面只是一个测试平台来说明,清单是一个相对布局中的标准 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);
}
}
那么如何在 loadDataWithBaseURL 之间强制等待 n 秒(在相同或不同的 WebView 上)?
蒂亚,
肯
I need some tutorial-level help with displaying WebView content in a timed sequence.
Below is just a testbed to illustrate, the manifest is a bog-standard WebView in a RelativeLayout.
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);
}
}
So how do I enforce a wait of n seconds between loadDataWithBaseURLs (on the same or different WebViews)?
TIA,
Ken
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
mWebView1.postDelayed(..., 超时);
或
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(命令、initialDelay、延迟、单位);
我认为任何计时器都可以,只需确保在 UI 线程上调用 webview 方法即可。
how about:
mWebView1.postDelayed(..., timeout);
or
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(command, initialDelay, delay, unit);
I think any timer will do, just make sure you call webview methods on UI thread.