我在webView中制作某种书籍阅读器。我使用了JavaScript,它通过for循环动态创建<img>
标记。查看代码的for循环,每个img标记都加载了与URL不同的图像。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
progressDialog = ProgressDialog.show(MainActivity.this,
"Loading Book...!", "Please Wait");
String htnlString = "<!DOCTYPE html><html><body style = \"text-align:center\"><script>var out = '';for (var counter = 1; counter <= 100; counter++){ out += '<img src=\"http://shiaislamicbooks.com/books_snaps/UR335/'+counter+'.jpg\"alt=\"Page No:'+counter+'\" width=\"100%\" />';}document.write(out);</script></body></html>";
wv.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Completed",
Toast.LENGTH_SHORT).show();
super.onPageFinished(view, url);
}
});
wv.loadDataWithBaseURL(null, htnlString, "text/html", "UTF-8", null);
}
查看htnlString
:
scrollTo(x,y)
是有用的,但我想要webview的滚动监听器。答案 0 :(得分:1)
WebView webview;
yPos = webview.getScrollY();
xPos=webview.getScrollX();