【发布时间】: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