【问题标题】:Remove white space at bottom of page xamarin.forms删除页面底部的空白 xamarin.forms
【发布时间】:2018-02-28 01:10:16
【问题描述】:

我有这个 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;

        }

    }

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

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

彼得

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    试试:

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

    默认情况下,网格会填充整个页面。如果您没有在 web 视图上设置任何水平或垂直选项,它应该填满整个网格。

    【讨论】:

    • 不幸的是,当我添加网格而不是 StackLayout 时,会出现同样的情况。
    • 奇怪。我会尝试创建一个测试应用程序,看看是否能找出原因。