删除页面底部xamarin.forms的空白区域

时间:2018-02-27 13:00:44

标签: xamarin.forms

我有这个Xamain.Forms应用程序,我在设备方向更改时隐藏页面标题。一切正常,但在Android上,当我切换到水平视图时,内容上方会显示一个空格。您可以在下面的图片中看到它的外观。

enter image description here enter image description here

这是我的xaml代码:

<?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="Kanal10Live.VideoTest">
<ContentPage.Content>
    <StackLayout x:Name="VideoStack">
        <WebView x:Name="Browser" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></WebView> 
    </StackLayout>
</ContentPage.Content>

这就是背后的代码:

private double width = 0;
    private double height = 0;
    protected override void OnSizeAllocated(double width, double height)
    {
        base.OnSizeAllocated(width, height);

        switch (Device.RuntimePlatform)
        {
            case Device.Android:
                if (width != this.width || height != this.height)
                {
                    this.width = width;
                    this.height = height;
                    if (width > height)
                    {
                        NavigationPage.SetHasNavigationBar(this, false);
                        VideoStack.Orientation = StackOrientation.Horizontal;                            
                    }
                    else
                    {
                        NavigationPage.SetHasNavigationBar(this, true);
                        VideoStack.Orientation = StackOrientation.Vertical;
                    }
                }

                break;

        }

    }

有趣的是,如果我在页面初始化时使用下面的代码就可以了。

如果有人可以帮助我,我将不胜感激!

彼得

1 个答案:

答案 0 :(得分:0)

尝试:

<Grid>
    <WebView x:Name="Browser" />
</Grid>

网格默认填充整页。如果您未在Web视图上设置任何水平或垂直选项,则应填充整个网格。

相关问题