【问题标题】:Android WebView, view.capturePicture().getHeight() is 0Android WebView,view.capturePicture().getHeight() 为 0
【发布时间】:2013-05-14 10:46:30
【问题描述】:

我正在使用 Android 4.0。我有一个 WebView,我想在其中捕获它的屏幕。 我覆盖 WebViewClient onPageFinished 如下:

@Override
public void onPageFinished(WebView view, String url) {
                Picture picture = view.capturePicture();
Toast.makeText(finplan.this, "picture height "+picture.getHeight()+ " url "+url, Toast.LENGTH_LONG).show();

在另一个过程中我调用了 loadUrl:

mywebview.loadUrl("http://www.google.com"); 
// this one works fine and picture.getHeight() is > 0

mywebview.loadUrl("file:///android_asset/test.html"); 
// this one works, but the picture.getHeight() retrieved in onPageFinished is always 0

test.html 是一个简单的 html 文件,我稍后注意到任何带有“http//”的 loadUrl 都可以正常工作,但不能在 'file://' 上工作。有什么帮助吗???

【问题讨论】:

    标签: android webview webviewclient


    【解决方案1】:

    将您的 .html 文件粘贴到项目文件夹的 assets 文件夹中。并使用 fol 代码在 layout 文件夹中创建一个 xml 文件:my.xml:

       <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@+id/webview"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
              />
    

    在活动中添加fol代码

    setContentView(R.layout.my);
    WebView mWebView = null;
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl("file:///android_asset/new.html"); //new.html is html file name.
    

    【讨论】:

      猜你喜欢
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 1970-01-01
      • 2012-12-11
      • 1970-01-01
      相关资源
      最近更新 更多