安卓 - webview 截断问题

4

我目前有一个webview,显示当前网站。然而,它截断了页面的侧边。请参见下面的图片。有没有办法解决这个问题?同时,请查看我的代码和xml。谢谢!

图片:

enter image description here

代码:

    // create alert dialog
    blogDialog = new AlertDialog.Builder(BlogActivity.this).create();

    // add progress bar support
    getWindow().requestFeature(Window.FEATURE_PROGRESS);

    // make progress bar visible
    getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
            Window.PROGRESS_VISIBILITY_ON);

    setContentView(R.layout.webtab);

    sdrWebView = (WebView) findViewById(R.id.sdrwebview);
    sdrWebView.getSettings().setJavaScriptEnabled(true);

    // set web view zoom
    //sdrWebView.setInitialScale(scaleInPercent)

    // set the width,zoom function, and other settings
    sdrWebView.getSettings().setUseWideViewPort(true);
    //sdrWebView.getSettings().getUseWideViewPort(true);
    sdrWebView.setInitialScale(0);
    sdrWebView.getSettings().setBuiltInZoomControls(false);
    sdrWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    sdrWebView.canGoBack();
    sdrWebView.getSettings().setAllowFileAccess(true);
    sdrWebView.getCertificate();

    // remove scrollbar
    sdrWebView.setVerticalScrollBarEnabled(false);

    // set the URL
    sdrWebView.loadUrl("http://www.stopdroprave.com");

    //enable flash
    sdrWebView.getSettings().setJavaScriptEnabled(true);

XML:

<RelativeLayout 
android:id="@+id/relativeLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical">
  <WebView
        android:id="@+id/sdrwebview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</RelativeLayout>
2个回答

2

这里有两种可能性:

  1. 检查父视图(即tabhost布局)中是否存在padding/margin。

  2. 在你的代码中添加以下内容:

<supports-screens android:smallScreens="true"
      android:normalScreens="true" 
      android:largeScreens="true"
  android:anyDensity="true" />

2
从您的图片中看,似乎您也在使用标签页。这可能是由于嵌入式 Webview 不知道其父元素的边界而导致的,它会占用屏幕的宽度而不是选项卡视图的宽度。
您可以通过几种方式来修复此问题,但可能最快/最简单的方法是调整 Webview 的边距以与选项卡布局相匹配。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接