android - 删除 webView 中的边距

标签 android webview

我对 webView 有疑问。正如您在图片上看到的那样,有白色边距。我想把那张照片填满我的屏幕。我该怎么做? 这是图片: enter image description here

这是代码:

    WebView web = new WebView(getContext());
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setBuiltInZoomControls(true);

String imagePath = id;
String html = "<html><body><img src=\""+ imagePath + "\"></body></html>";
web.loadDataWithBaseURL("file:///mnt/sdcard/DinEgen/", html, "text/html","utf-8",null);
web.setPadding(0, 0, 0, 0);

web.setInitialScale(1);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
web.setScrollbarFadingEnabled(false);

XML 文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:weightSum="100">

        <android.support.v4.view.ViewPager
        android:id="@+id/presentation_viewPager"
        android:layout_width="match_parent"
        android:layout_height="0dp" 
        android:layout_weight="95"

        />
    <LinearLayout
        android:id="@+id/presentation_indicatorLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp" 
        android:layout_weight="5"
        android:gravity="center"
        android:background="@drawable/choose_small_normal"
        >
    </LinearLayout>
</LinearLayout>

最佳答案

用这个替换你的标签:

<body style='margin:0;padding:0;'>

这是关于 WebView 中图像的另一个提示: 添加适合屏幕宽度的图像样式。适用于所有屏幕尺寸:

<style type='text/css'>
       img {max-width: 100%;height:initial;} div,p,span,a {max-width: 100%;}
       </style>

关于android - 删除 webView 中的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11411009/

相关文章:

android - Android的WebView可以自动调整大图的大小吗?

ios - Xcode VisualEffectView 阻止与其他 View 交互

android - 如何在源代码管理下处理 Android Gradle 文件?

android.database.sqlite.SQLiteException : near "Order": syntax error (code 1):

ios - 在 Xcode 中使用 Swift 确定在 webView 中完成加载网站

android - 如何使用 session ID和用户ID详细信息在Webview中保持登录到我的域URL

android - 无法将大图像加载到 web View android

Android 无法使用 AVRDUDE 与 Arduino 对话

android - 分频器在扩展时消失

android - Android Studio 中的 LLDB 究竟是什么?