0

我正在 webView 中制作某种图书阅读器。我使用了 JavaScript,它<img>通过 for 循环动态创建标签。查看代码的 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

  • 现在我想在 textView 中显示一本书的页面信息。这意味着,在滚动 webview 时,textView 应该更新 txtPage。
  • scrollTo(x,y)是一些有用的,但我想要 webview 的滚动侦听器。
4

1 回答 1

1
WebView webview;
yPos = webview.getScrollY();
xPos=webview.getScrollX();
于 2013-01-10T11:03:55.953 回答