WebView为什么不显示?我已经尝试了FillAndExpandCenterAndExpand,但是仍然无法正常工作!

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:views="clr-namespace:MyApp.Views;assembly=MyApp"
             x:Class="MyApp.Pages.Main">
  <StackLayout>
    <StackLayout Orientation="Horizontal" VerticalOptions="Start">
      <!-- top controls -->
    </StackLayout>

    <StackLayout x:Name="WebViewLayout" VerticalOptions="CenterAndExpand">
      <WebView Source="https://www.google.com/" VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand"/>
    </StackLayout>

    <StackLayout Orientation="Horizontal" VerticalOptions="End">
      <views:AdMobView WidthRequest="400" HeightRequest="50" />
    </StackLayout>
  </StackLayout>


</ContentPage>

最佳答案

我建议从父WebView中取出StackLayout,并将最外面的StackLayout更改为Grid

话虽这么说,但我认为这样做可能有助于解决问题:

public override void OnAppearing()  {
    SizeChanged += (sender, e) => {
        WebViewItem.WidthRequest = Width;
        WebViewItem.HeightRequest = 200; //Or what ever
    }

    OnSizeChanged(null, null); //Make it run at least once
}

关于android - Xamarin表单-Webview未显示在我的StackLayout中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37621609/

10-10 01:23