【问题标题】:Why did modifying the WebView Layout Parameter fix the 0 height body issue?为什么修改 WebView 布局参数可以解决 0 高度 body 问题?
【发布时间】:2017-09-29 08:57:08
【问题描述】:

我有一个未正确显示我的 HTML 的 Xamarin WebView。它被设置为填满整个屏幕,但是 HTML 中的 body 高度仍然是 0px。

我在 html 中也有一个 div 样式:

position:absolute; top:0px; bottom:0px; left:0px; right:0px;

这也是 0px 高。

我尝试了以下选项:

  webView.SetInitialScale(1);
  webView.Settings.LoadWithOverviewMode = true;
  webView.Settings.UseWideViewPort = true;

这没有帮助,但我注意到 webView.LayoutParameters.Height 出于某种原因是 -2。

我添加了这段代码,突然我的绝对定位的 div 有了高度。

    protected override void OnSizeChanged(int w, int h, int oldw, int oldh) {
        webView.LayoutParameters.Height = -1;

        base.OnSizeChanged(w, h, oldw, oldh);
    }

-2 有什么特别之处?为什么更改布局参数会突然强制 HTML 按预期呈现?

【问题讨论】:

    标签: android css xamarin webview xamarin.forms


    【解决方案1】:

    在 iOS 中,您最初需要设置 HeightRequest。对一些小事。以便创建滚动视图。

    webview.HeightRequest = 20;

    // 代码在这里

    【讨论】:

      猜你喜欢
      • 2019-06-11
      • 1970-01-01
      • 2019-08-29
      • 2012-01-20
      • 2022-12-08
      • 1970-01-01
      • 2013-05-14
      • 2019-11-16
      • 2015-03-31
      相关资源
      最近更新 更多