Xamarin Android - 如何摆脱 WebView 周围莫名其妙的 Margin/Padding?

Xamarin Android - How to get rid of inexplicable Margin/Padding around a WebView?

我有一个 LinearLayout,其中包含一个 WebView。此 WebView 加载静态 HTML 文件。我希望 WebView 的大小(宽度和高度)与 LinearLayout 的大小相匹配,但由于某些莫名其妙的原因,存在阻止 WebView 填充 LinearLayout 的神秘边距或填充。为了说明,我给 LinearLayout 设置了黑色边框,并为 WebView 加载的 HTML 文件的内容设置了红色边框:

以下是这些元素的 axml:

<LinearLayout
        android:id="@+id/alertViewProductReplacement_ReplacementProductLinearLayout"
        android:layout_width="100dp"
        android:layout_height="225dp"
        android:layout_margin="0dp"
        android:padding="0dp"
        android:fillViewport="true"
        android:layout_toRightOf="@id/alertViewProductReplacement_arrow"
        android:background="@drawable/dpBorder"
        android:orientation="vertical">
        <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/replacementProductsWebView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:fillViewport="true"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:background="@null"/>
</LinearLayout>

我已经尝试在上面指出的一些可能多余的事情是将两者的边距和填充设置为 0,将 WebView 的高度和宽度设置为 "fill_parent",并设置 fillViewport="true".我还尝试以编程方式强制 0 边距和填充,以及将 LinearLayout 更改为 RelativeLayout。 None 这些东西有任何效果,它们之间的少量 space 看起来总是一样。

我还要指出,HTML 内容本身在红色边框之外没有边距或填充,如果我直接在浏览器中加载 HTML 文件,可以清楚地看到这一点:

我什至试图通过在 axml 级别和 HTML 文件级别设置负边距来暴力破解它,但我无法让那个神秘的边距让步 no不管我怎么努力,所以我终于转向了这里。

WebView 网络浏览器,并且在正文中有一些默认边距(与其他网络浏览器一样)。您可以像这样使用 CSS 删除该边距:

<body style="margin:0;">

更多信息:Remove unwanted White Space in WebView Android