简体   繁体   English

Xamarin Forms,Webview 在 Content 的顶部留下一个缺口

[英]Xamarin Forms, Webview leaves a gap at the top of the Content

When I use a webview, it has gaps at the top and bottom, or if orientated horizontally it has gaps at the side.当我使用 webview 时,它在顶部和底部有间隙,或者如果水平方向它在侧面有间隙。 How do I make the webview fill the entire screen.如何让 webview 填满整个屏幕。

You can see in the screenshot the blue area is the background color of the content.您可以在屏幕截图中看到蓝色区域是内容的背景颜色。 Why doesn't the webview start at the top?为什么 webview 不从顶部开始?

I have also added a label which correctly strats at the top of the screen.我还添加了一个标签,它在屏幕顶部正确排列。

    <?xml version="1.0" encoding="UTF-8"?>
       <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
         x:Class="WorkingWithWebview.MyPage" >
       <ContentPage.Content>
           <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
             <Label Text="this is a label showing its not the nav bar" BackgroundColor="Red"></Label>
             <WebView VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" 
             Source="https://www.google.com" WidthRequest="1000" HeightRequest="1000">

           </WebView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

在此处输入图片说明

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ContentPage.Content>
    <Grid HorizontalOptions="FillAndExpand"
          VerticalOptions="FillAndExpand">
        <WebView HorizontalOptions="FillAndExpand"
                 VerticalOptions="FillAndExpand">
            <WebView.Source>
                <HtmlWebViewSource Html="{Binding TermsAndConditions}"/>
            </WebView.Source>
        </WebView>
    </Grid>
</ContentPage.Content>

This setup works well for me =)这个设置对我很有效=)

I had the same issue.我遇到过同样的问题。 If you set an iOS storyboard for your app, the gap will be gone.如果你为你的应用设置了一个 iOS 故事板,这个差距就会消失。 The app will be sized based on the size of the launch screen or story board.应用程序将根据启动屏幕或故事板的大小调整大小。 Of nothing is set, it will leave a gap for large iPhone screen sizes.没有设置,它将为大尺寸 iPhone 屏幕留下空白。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM